Python Final

Ace your homework & exams now with Quizwiz!

What is the output of the following code snippet when the user enters 100 as the grade? grade = int(input("Enter student grade: ")) if grade >= 90 : letterGrade = "A" if grade >= 80 : letterGrade = "B" if grade >= 70 : letterGrade = "C" if grade >= 60 : letterGrade = "D" else : letterGrade = "E" print(letterGrade)

D

Which of the following symbols can be used to begin a string literal in Python?

"

What is displayed by the following code segment? print("\"Hello World!\"")

"Hello World!"

What is the value of words after the following code segment? words = "Hello" + "World" * 3

"HelloWorldWorldWorld"

Consider the following code segment: title = "Python for Everyone" newTitle = title.replace("e", "*") After this code runs, the value stored in newTitle is:

"Python for Ev*ryon*"

Which of the following is considered a string in Python?

"Today is Wednesday"

What symbol is used to begin a comment in a Python program?

#

Which of the following statements correctly calculates the average of three numbers: num1, num2, and num3?

(num1+num2+num3)/3

Consider the following code segment: x = 5 y = 7 z = x - y * 2 After this code segment executes, the value of z is:

-9

What extension is used for Python files?

.py

What is the index value of the letter 'h' in the string below ? message = "hello"

0

What is the value of result after the following code snippet? num1 = 10 num2 = 20 num3 = 2 result = num1 // num2 // num3 print(result)

0

What is the value of result after the following code snippet? num1 = 10 num2 = 20 num3 = 2 result = num1 / num2 / num3 print(result)

0.25

Consider the following code segment: x = 100 print("%d%%"%x)

100%

What is printed by the following code snippet? print(25 + 84)

109

What is the value of length after this statement? length = len("Good Morning")

12

Consider the following code segment: x = 5 y = 3 z = 2 result = x // y + x % z After this code segment, the value of result is:

2

What is the value of result after the following code snippet? num1 = 300 num2 = 20 num3 = 7 result = num1// num2//num3 print(result)

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 2 at the first prompt and 3 at the second prompt. The output displayed is:

2 3

What is printed by the following code snippet? print("2+3")

2+3

What is printed by the following code snippet? print("25 + 84")

25 + 84

Consider the following program: def main() : a = 3 doubleIt(a) print(a) def doubleIt(x) : return x * 2 main()

3

What is returned by the function: round(3.14159, 2)?

3.14

What values does counter variable i assume when this loop executes? for i in range(30, -10, -10) : print(i, end = " ")

30 20 10 0

Consider the following program: def main() : a = 3 print(doubleIt(a)) def doubleIt(x) : return x * 2 main()

6

What is returned by the following function if x = 5.64? round(x)

6

What is returned by the function: round(x) if x = 5.50?

6

What is the value of the variable num after the following code snippet? num = 5 num2 = 6 num = num2 + 3

9

What is wrong with the following code snippet? result = num1 // num2 / num3 num1 = 20 num2 = 10 num3 = 2 print(result)

A variable is used before it is assigned a value.

What is the difference between an editor and an interpreter?

An editor allows program files to be entered and modified; an interpreter reads and executes program files

What is printed by the following code snippet? print("Good", "Morning", "Class", "!")

Good Morning Class !

What range of numbers are generated by the random() function?

Greater than or equal to zero and less than one

Which line in the following program is a comment line?\

Line number 3

Which type of error is usually the most difficult to locate in your program?

Logic Error

What is printed by the following code snippet: street = "Main Street" address = 94089 + street print(address)

Nothing is printed, this code snippet causes an error

What is printed by the following code snippet? print(Hello)

Nothing, an error is produced indicating that Hello is not defined

What is the output from the following Python program? def main() : a = 10 r = cubeVolume() print(r) def cubeVolume() : return r ** 3 main()

Nothing, there is an error.

What is wrong with the following code snippet: num1 = 10 num2 = 20 num3 = 30 total = Num1 + Num2 + Num3

Python is case sensitive so Num1, Num2, and Num3 are undefined

What is another name for compile-time error?

Syntax error

What is wrong with the following code snippet? 2ndNum = 78

The 2ndNum variable is not a valid variable name

What is printed by the following code snippet? print("The answer is", 25 + 84)

The answer is 109

What is printed by the following code snippet? print("The answers are:", 4 + 3 * 2, 7 * 5 - 24)

The answers are: 10 11

Although the following code statement is valid, print(10/0), what will happen when this code is executed?

The error message ZeroDivisionError: int division or modulo by zero is displayed

What is wrong with the following code snippet? mystery(10, 2) def mystery(num1, num2) : result = num1 ** num2 return result

The function must be defined before the statement that calls it

What is wrong with this assignment statement? num + 10 = num2

The left hand side of an assignment statement cannot include an operator.

When the computer begins to run a program,

The program is moved from CPU to secondary storage

What is wrong with the following code snippet? print("Hello") print("World!")

The second line should not be indented

What is printed by the following code snippet? name = "today is thursday" name = name.replace("t", "T") name.replace("i", "I") print(name)

Today is Thursday

What is wrong with the following code? def grade(score) : if score >= 90 : return "A" elif score >= 80 : return "B" elif score >= 70 : return "C" elif score >= 60 : return "D"

Another |return| statement needs to be added to the function

What is printed from the following code snippet: message = "ho.." print(message * 3)

ho..ho..ho..

Which statement finds the last letter of the string variable name?

last_letter = name[len(name) - 1]

Which statement correctly creates a new variable by combining the two string variables: firstName and lastName?

name = firstName + lastName

What is printed by the following code snippet: street = " Main Street" address = 123 + street print(address)

nothing is printed, this code snippet causes an error

What output is generated by the following code snippet? firstName = "Pamela" middleName = "Rose" lastName = "Smith" print(firstName[0], middleName[0], lastName[5])

nothing, this causes an index of bounds error

Which of the given print statements generates the following output? ABCDE"\

print("ABCDE\"\\")

Which of the following code segments will display Hello World! when it is run?

print("Hello", "World!")

Which parts of the computer store program code?

secondary storage

What is the correct sequence of steps invoked by the Python Interpreter:

source code -> compiler -> byte code -> virtual machine

What is another name for a compile-time error?

syntax error

What is printed by the following code snippet? name = "today is thursday" name.replace("t", "T") name.replace("i", "I") print(name)

today is thursday

Consider a function named |calc|. It accepts two string arguments and returns their sum as an integer. Which of the following statements is a correct invocation of the calc function?

total = calc("4", "5")

Which of the following statements causes Python to report an error?

x = 17 + "18.4"

Which line of code creates a variable named x and initializes it to the integer 5?

x = 5

Which line of code will generate a random integer from 0 up to and including 10, and store it in |x|? Assume that the |randint| function has been imported from the |random| module.

x = randint(1, 11) ** Not sure about this one **

Given the code snippet below, what is returned by the function call: |mystery(mystery(2, 3), mystery(1, 2))|? def mystery(num1, num2) : result = num1 * num2 return result

|12|

Which of the following statements correctly defines a function?

|def functionName(parameterName1, parameterName2) :|

Using De Morgan's law, what is the equivalent to this statement? if not (state != "PA" and state == "OH")

|if state == "PA" or state != "OH"|

Which function call will cause Python to report an error?

abs(1, 2)

What is supplied to a function when it is called?

arguments

Which of the following names is not a legal variable name?

bottle-volume

Which of the following statements draws a circle?

canvas.drawOval(200, 100, 200, 200)


Related study sets

Chapter 10: The Nervous System: Introduction. Quiz.

View Set

Mathematics 700 Fundamentals - Unit 9: Measurement and Area CIRCUMFERENCE

View Set

CCNA LAN Switching and Wireless Chapter 9

View Set

Krueger, Explorations in Economics 1e, Module 13

View Set

respiratory exam practice questions

View Set

NURS 212 -- Chapter 14 PrepU Review

View Set