actual quiz 2 study set

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

how does python say something is not equal to something?

!=

multiplication operator

*

what is print(5 + 7 - 10 * 3 / 0.5)? print((5 ** 8) - 7 **** 2 - (-1 ** 18))? print(9 / 3 + (100 ** 0.5) - 3)?

-48.0, 9, 10.0

Which of the following operators cannot be used with strings?

/

What is False equal to?

0

what is True equal to?

1

Which operation should be performed first in the following expression? 7 / 2 + (5 % 2 ** 5) *** 2 - 3 5 % 2 * 5 7 / 2 5 % 2 5 ** 2

5 % 2

How do you put a number to the power of something

5 ** 2

What does this print out? a = 10 b = 3 c = a - b print(c)

7

a = 10 b = 3 a -= b print(a)

7

What raises 7 to the power of 4? 7 * 4 7 ** 4 7 ^ 4 4 ** 7

7 ** 4

How does python say something is less than something?

<

How does python say something is less than or equal to something?

<=

How does python say something is greater than something?

>

How does python say something is greater than or equal something?

>=

What is a compound conditional?

A conditional that has two or more boolean expressions.

what is the elif syntax rules?

An if statement must come before the first elif statement elif is followed by a boolean expression and a : Indent four spaces and write the commands for when the elif statement is true You can write as many elif statements as you want An else statement must come after the last elif statement

Why are == , < , <= , > , >= called boolean operations?

Because the result is a boolean value (True or False) no matter what.

What data type is used by a conditional to know which part of the code should be executed? Boolean Integer Float String

Boolean

What is output from the following code? day = "Thursday" homework_done = False if day == "Saturday": if homework_done: print("Go to movie") else: print("Do your homework!") print("Can't wait for the weekend")

Can't wait for the weekend

What is output from the following code? day = "Tuesday" homework_done = True if day == "Saturday" and homework_done == True: print("Go to movie") else: print("Do your homework!") print("Can't wait for the weekend")

Do your homework! Can't wait for the weekend

What does an if statement not do?

Evaluates code when the boolean expression is false.

Evaluate 5 ** 2 > (8 / 2) ** 2 and 10 % 4 > 3 True or False?

False

What is the result of the following expression? not (5 != 3) and (5 % 3 >= 2)

False

Select all of the statements below that are true with regards to if statements. Hint, there is more than one correct answer. If statements will perform a set of actions if the boolean expression is false. If statements provide the most numeric precision of all the conditional statements. If statements only ask if a boolean expression is true. If statements are the simplest of all the conditionals.

If statements only ask if a boolean expression is true. If statements are the simplest of all the conditionals.

And operator rule

If the first boolean expression for the and operator is false, then the entire thing is false. The second boolean expression is ignored.

Why might you want to use a compound conditional?

If two or more things have to be true. When you want your code to be more concise and easy to read.

what happens if you print a = 3 b = "Hello!" print(a * b)

It prints hellohellohello, when you multiply strings with a number x (MUST BE A POSITIVE INTEGER) it repeats the string x amount of times.

How does branching effect the flow of code?

It still executes top to bottom but then reach a decision and then it chooses a code.

What order of operations does python use?

PEMDAS (Parentheses, exponents, multiplication and division and modulo, and addition and subtraction)

What are conditionals?

Pieces of code that make a decision about what the program is going to do next. The common conditional is the if statement.

Looking at the expression below, identify the order of operations. (1 + 2) ** 4 *** 2 - 10

Step 1: 1 + 2 Step 2: 4 ** 2 Step 3: 3 * 16 Step 4: 48 - 10

What does the "if else" statement do ?

The if statement executes a statement if a specified condition is true. If the condition is false, another statement can be executed.

The not operator

The not operation produces the opposite of the boolean expression so print (not True) prints out false.

Modulo pattern

The only possible outcomes are 0 through that integer minus 1 when you divide something.

What are the requirements of using an else statement?

There is no indentation Use a : at the end Do not use another boolean expression Code after the else must be indented

What is wrong with the code below? if 3 > 4 print("This is true") else print("This is false")

There needs to be an : after the if and else statement. and the print statement needs to be indented.

What do if statements do?

They test to see if a certain condition is true, If it is then specific commands are run. A simple if statement does not do anything if false.

Evaluate (7 >= 7) and (True or 99 < 1) or not (3 > 5 and 7 < 10) and 2 != 4 True or False?

True

What is floor division?

Using the // operation , it removes the decimal value from the answer so 9/2 which equals 4.5 if you do 9 // 2 it would give only 4.

Or operator rule

When using the or operator, Python checks to see if the first boolean expression is true. If it is true, Python returns true and ignores the second boolean expression.

How do you do division?

With the / or the /= operator. It will always return a float.

Are strings stored as numbers behind the scenes?

Yes but they are encoded by something called the ascii table(120 different characters)

Can floor division return a float?

Yes if one of the values is a float but the decimal part will always be .0

Which of the following type of questions is the most accurate to describe what happens with branching in a computer program? Multiple Choice question Fill in the blank question Yes/No question

Yes/No question

Why might you NOT want to use a compound conditional?

You have multiple conditions that depend on other conditions involving several variables. When you want your code to be more understandable and easy to read.

What are the values of a and b such that the following expression is true? a * 3 + b - 8 / 2 is equal to 17.0

a = 4 and b = 9

why is it sometimes better to use a + instead of comma when putting multiple arguments in a print function.

a comma adds a space so if im trying to add a exclamation point I can do "whatever" +"!" to get whatever! but if I did "whatever" , "!", I'd get whatever !

Why is an elif statement more efficient then a series of if statements?

a series of elif statements can be more efficient that a series of if statements because the elif statements will stop as soon as there is a true boolean expression. The if statement, however, will keep going even if there is a true boolean expression.

The and operator

allows for a compound boolean expression. All must be true for it print out true.

The or operator

allows for compound boolean expressions if only one boolean expressions is true than the whole is true. All must be false to be false.

Which of the following keywords allows you to have more than 2 branches with a single conditional statement?

elif

Which of the following elifstatements is correct?

elif a < 10:

multiple and statements

evaluated left-to-right manner.

Type Casting

forces a value of one data type to be used as a value of another data type

What does the statement need to be a complete if statement? ____num > 100 ____ print("num is greater than 100")

if and :

Construct code that will print out messages based on the weather: "Bring an umbrella!" if it is rainy but not windy "Wear a rain jacket." if it is rainy and windy "You might need a coat." if it is cold but not rainy "Enjoy your day!" if it is not cold and not rainy

if rainy: if windy: print("Wear a rain jacket.") else: print("Bring an umbrella!") else: if cold: print("You might need a coat.") else: print("Enjoy your day!")

Which of the following pieces of code will print a message that it's comfortable if the temperature is between 65 and 75 degrees Fahrenheit, and a message that it is too hot or cold if it's outside that range. 65 andf 75 are included in the "comfortable" range. Assume there is a variable named temp that holds the current temperature.

if temp <= 64 or temp >= 76: print("It is too hot or too cold!") else: print("The temperature is comfortable")

what is +=

incrementing a variable/aka adding it.

What type of question does an elif statement ask?

is this true or is this false? it gives you more precision when making decisions.

what is -=

it decrements a variable/aka subtracting it.

what does modulo = 5 % 2 print(modulo)

it prints out 1, because 5/2 is 2 and 1/2 it takes the 1 and ignores the rest.

what is the purpose of a variable

its to help store and keep tracks of values like passwords or usernames, the main two types of values are number types (int and float) and character types(strings).

What is a TypeError in python

means that when the computer/interpreter is trying to put too things together but they aren't the same.

modulo

module operation is % and only returns the remainder after division is performed.

can you subtract strings like how you can add them?

no you cannot.

Select the line of code below that prints the product of the variables a and b. print(ab) print(a * c) print(a x b) print(a * b)

print(a * b)

Given the variables below, determine which print statement would return False. a = True or False b = False and True c = False and False

print(not b and not a or not not c)

How to check for type

print(type(x)) with x being a certain function

What do if statements in python must contains?

the keyword if a boolean expression a colon 4 spaces (1 tab) of indentation for all lines of code that will run if the boolean expression is true.

How do programmers use Logic

the way in we resolve a question, these questions to have true or false questions. If something is true then the program will do one thing and if its false it will do another.

How does python determine equality?

with the == operator

can you add ints and floats together? Can you add booleans and ints?

yes and the answer is a float. Yes you can but try not to.

How do you take the square root?

you do ** 0.5

What is branching?

you want to have set of instructions that execute under one set of conditions and another set of instructions that execute in another set of conditions


संबंधित स्टडी सेट्स

Chapter 4: Labor and Financial Markets

View Set

Terraform - Providers Within Modules

View Set

Chapter 4 - Managing in a Global Environment

View Set

Quiz: Assessing the Apical Pulse by Auscultation

View Set