programming midterm
In Python the not equal relationship operator is?
!=
Which statement is true based on the rules of relationship operators and comparing text using the Python language?
"Ford" >= "FORD"
Which of the following expressions correctly determines that x is greater than 10 and less than 20?
(10 < x) and (x < 20)
What conditional statement is used to express the following? Both X and Y are positive or both X and Y are negative.
(X>0 and Y>0) or (X<0 and Y<0)
Which mathematical operator is used for integer division in Python?
//
What will be the output of the following line of code: print(format(1234.567, ',.2f'))
1,234.57
What is the output of the following program? x = -2 y = 7 if x != y: y = x z = y / x else: x = y z = y // x print(z)
1.0
To this point we have looked at the str, int and float data types. Chapter 3 introduces the Boolean datatype. How many values can a Boolean variable reference?
2
A blank space is represented by the number ____ on the ASCII code?
32
In and "or" multiple conditional statement in order for the whole condition to return "True"....
Any one part of the "or" condition needs to be "True"
If an if-elif-else statement the number of elif conditions allowed in one if-elif-else statement is?
As many as needed
What is the output if the user enter the numeric 12 for input of the following code? age = int(input('Enter age: ')) if age <= 1: print('Infant') else: if age > 1 and age <= 12: print('Child') else: if age >= 12 and age < 20: print('Teenager') else: print ('Adult')
Child
In a flowchart what symbol represents a decision structure?
Diamond
a = 4 b = 7 c = 10 Based on the above variables what is the output of the following: ((a < b) or (a < c)) and (not(c > b) and (b < c))
False
What is the output of the following code ? num = 5 if (num == 2): print("Two") elif num > 3: print("Great") elif num == 5: print("Equal") Select one:
Great
This block of code allows a program to decide on a course of action based on whether a certain condition is true or false?
If Block
The Python ____________ executes lines of code in a Python program by converting the code into machine language a computer understands.
Integrated Development Environment (IDLE)
With the code below. What is the output if the user enters in a numeric 5 for input? weight = 0.0 shippingCost = 0.0 weight = float(input('Enter the weight of the package: ')) if weight > 10: shippingCost = 4.75 elif weight > 6: shippingCost = 4.00 elif weight > 2: shippingCost = 3.00 else: shippingCost = 1.50 print ('Shipping charge: $', format(shippingCost, '.2f'))
Shipping charge
What is the output of the output of the following code? num1 = 5 if (num1 >= 2): print(num1) else: num2 = 8 print(num2) print(num2)
Syntax Error
Consider the following 2 sets of code: Example (a): a = 1 b = 1 if (a == 1) and (b == 1): print("Hi") Example (b): a = 1 b = 1 if (a == 1): if(b == 1): print("Hi")
The two sets of code are equivalent
What is the output of the following code: x = 3 y = 3 if x > y: z = x + y else: z = y - x
There is no output
When writing "if" statements within "if" statements in Python which of the following below is false?
There needs to be a semicolin at the end of each "if" clause and "else" clause
An "if" block of code does not need the "else" portion of the code to be valid syntax but, if used there can only be one "else" portion?
True
Based on the following code what Boolean value is returned from the conditional expression that follows (based on x = 5): (x > 10) or (x >= 5) and (x <= 6)
True
What is the Boolean output of the following code: str1="GAry" str2="gAil" NOT(str1 > str2)
True
A Boolean ______ variable is a variable that signals when some condition exists in a program. When this variable is set to False it signals the condition does not exist and when set to True it signals the condition does exist.
flag
After the execution of the following statement, the variable sold will reference the numeric literal value as (n) ________ data type.sold = int(256.752)
float
Based on the variable assignment statements: a = 5 b = 6 Which code below is valid code in Python?
if (a==b):
Which is the correct format of an IF statement (assuming the "temp" variable has been declared and assign a value)?
if (temp < 40): print("A little cold isn't it") else: print("Nice weather we're having")
and, not and or are considered _____________?
logical operators
When an "if" statement is the true or false part of another "if statement they are?
nested if statement
In Python the following are considered __________ __________. >, >=, <, <=, == and !=
relationship operators
When using the "and" operator, if the expression on the left side of the "and" operator is false, the expression on the right side will not be checked. Because the compound expression will be false if only one of the subexpressions is false, it would waste CPU time to check the remaining expression. When using the "or" operator, if the expression on the left side of the "or" operator is true, the expression on the right side will not be checked. Again, to not waste CPU time. In our textbook this is defined as ________ evaluation.
short-circuit
Which type of programming error prevents the program from calculating correct output based on the requirements of the program?
syntax
What is the output of the following code? if ("cat" > "Cat") and ("Dog" < "dog"): print("yes") else: print("no")
yes