Python Quiz 2
What is returned by the following function if x = 5.64? round(x) 1) Nothing, there is an error in the statement 2) 5 3) 5.6 4) 6
4
What is returned by the function: round(3.14159, 2)? 1) 3 2) 3.14159 3) 3.2 4) 3.14
4
What is the value of the result after the following code snippet? num1 = 10 num2 = 20 num3 = 2 result = num1 / num2 / num3 print(result) 1) 1 2) 0 3) The code has an error 4) 0.25
4
What is printed by the following code snippet: street = " Main Street" address = 123 + street print(address) 1) 123Main Street 2) 123 Main Street 3) 123 "Main Street" 4) nothing is printed, this code snippet causes an error
4
Which statement draws a square on the canvas? 1) canvas.drawRect(0, 50, 0, 50) 2) canvas.drawRect(50, 50, 0, 0) 3) canvas.drawRect(0, 0, 50, 100) 4) canvas.drawRect(0, 0, 50, 50)
4
Which statement finds the last letter of the string variable name? 1) last_letter = name[len(name)] 2) last_letter = len(name) - 1 3) last_letter = len(name) 4) last_letter = name[len(name) - 1]
4
Which line of code creates a variable named x and initializes it to the integer 5? 1) x = 5.0 2) x = 5 3) x = '5' 4) x = "5"
x = 5
Which function call will cause Python to report an error? 1) abs(1, 2) 2) max(1, 2) 3) min(1, 2) 4) round(1, 2)
1
Consider the following code segment: x = 5 y = 7 z = x - y * 2 After this code segment executes, the value of z is: 1) -9 2) -4 3) 5 4) 7
1
What is printed by the following code snippet? name = "today is thursday" name.replace("t", "T") name.replace("i", "I") print(name) 1) today is thursday 2) Today is Thursday 3) Today Is Thursday 4) Today Is thursday
1
What is the value of words after the following code segment? words = "Hello" + "World" * 3 1) "HelloWorldWorldWorld" 2) "Hello World World World" 3) "HelloWorldHelloWorldHelloWorld" 4) "Hello World Hello World Hello World"
1
What is wrong with this assignment statement? num + 10 = num2 1) The left-hand side of an assignment statement cannot include an operator. 2) Nothing, this statement compiles and executes. 3) The value of 10 must be defined before this statement can be executed. 4) The num variable must be defined before this statement can be executed
1
Which of the following names is not a legal variable name? 1) bottle-volume 2) cans_per_pack 3) four 4) x2
1
Which output format string correctly allows for 5 positions before and two digits after the decimal point? 1) "%8.2f" 2) "%5.2f" 3) "%7.2f" 4) "%5d.2f"
1
What is the index value of the letter 'h' in the string below? message = "hello" 1) 1 2) 0 3) 3 4) 4
2
What is the value of result after the following code snippet? num1 = 10 num2 = 20 num3 = 2 result = num1 // num2 // num3 print(result) 1) 1 2) 0 3) The code has an error 4) 0.25
2
What is wrong with the following code snippet? result = num1 // num2 / num3 num1 = 20 num2 = 10 num3 = 2 print(result) 1) A variable is used before it is assigned a value. 2) Nothing, the code compiles and runs. 3)The // symbol cannot be used in a Python program. 4) One or more of the variable names is not valid.
2
Which of the following statements causes Python to report an error? 1) x = 17 + 18.4 2) x = 17 + "18.4" 3) x = 17 + int(18.4) 4) x = 17 + float("18.4")
2
Which of the following symbols can be used to begin a string literal in Python? 1) * 2) # 3) " 4) >
2
Which statement correctly creates a new variable by combining the two string variables: firstName and lastName? 1) name = "firstName" + "lastName" 2) name = firstName + lastName 3) name = first name + last name 4) name = firstName & lastName
2
Consider the following code segment: a = input("Enter the value of a: ") b = input("Enter the value of b: ") print(a + b) When this code segment is run the user enters 1 at the first prompt and 5 at the second prompt. The output displayed is: 1) 1 2) 6 3) 15 4) 1 + 5
3
Consider the following code segment: title = "Python for Everyone" newTitle = title.replace("e", "*") After this code runs, the value stored in newTitle is: 1) "Python for *veryone" 2) "Python for Ev*ryone" 3) "Python for Ev*ryon*" 4) "Python for *v*ryon*"
3
What is printed from the following code snippet: message = "ho.." print(message * 3) 1) ho..ho..ho 2) ho.. 3) ho..ho..ho.. 4) nothing is printed, this code snippet causes an error
3
What is the value of length after this statement? length = len("Good Morning") 1) 10 2) 11 3) 12 4) 13
3
What is wrong with the following code snippet? 2ndNum = 78 1) The 2ndNum variable is never assigned a value 2) The 2ndNum variable is assigned a non-numeric value 3) The 2ndNum variable is not a valid variable name 4) The 2ndNum variable is never initialized
3
What symbol is used to begin a comment in a Python program? 1) ! 2) @ 3) # 4) $
3
Which of the following statements correctly calculates the average of three numbers: num1, num2, and num3? 1) num1 + num2 + num3 / 3 2) num1 + num2 + num3 % 3 3) ( num1 + num2 + num3 ) / 3 4) ( num1 + num2 + num3 / 3 )
3