Midterm

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

A Python paragraph comment uses the style ______. // comments // /* comments */ /# comments #/ comments ''

"comments"

A Python line comment begins with__________.

#

random.randint(0, 1) returns _________. 1 0 2 0 or 1

0 or 1

What is the value of result after the following code executes ? a = 60 b = 15 result = 10 if (a == b): result *= 2 20 10 code will not execute 120

10

Suppose that the variable x has the value 5 and y has the value 10. After executing these statements: x = y y = x what will the values of x and y be, respectively? 5 and 5 10 and 5 5 and 10 Correct! 10 and 10

10 and 10

What is the value of donuts after the following statements execute? donuts = 10 if (donuts != 10): donuts = 0 else: donuts += 2 0 1 None of these 12 10

12

After the following code executes, what is the value of my_value if the user enters 0? my_value = eval(input("Enter a number: ")) if (my_value > 5): my_value = my_value + 5 elif (my_value > 2): my_value = my_value + 10 else: my_value = my_value + 15 0 5 15 10

15

Which of the following statements will cause an error? x = "17" x = 9999 17 = x x = 17

17=x

If num1 is 2.0 and num2 is 12, what is the output of the following command? print (num1*num2) num1*num2 24.0 2.0*12 24

24.0

What is the result of evaluating 7//2? 1 2 3 5

3

Which of the following expressions is used to raise five to the second power in Python? 5~2 5**2 5/2 5^2

5**2

After the execution of the following statement, the variable price will reference the value _________. price = int(68.549) 68.54 68.55 69 Correct! 68

68

What is the result of eval("1+3*2") ? 8 7 "1 + 6" "1 + 3 + 2"

7

In Python, the ______ symbol is used as the equality operator. = <= >= ==

==

Which of the following code is correct? A. print("Programming is fun") print("Python is fun") B. print("Programming is fun") print("Python is fun") C. print("Programming is fun") print("Python is fun") D. print("Programming is fun) print("Python is fun")

A. print("Programming is fun") print("Python is fun")

What will be displayed by the following code? isCorrect = False print("Correct" if isCorrect == True else "Incorrect") Correct Incorrect Incorrect nothing Correct

Incorrect

__________ is interpreted.

Python

T/F In Python the first character of a variable name cannot be a number.

T

Analyze the following code: even = False if even = True: print("It is even!") The program has a syntax error in line 1 (even = False) The program has a syntax error in line 2 if even = True is not a correct condition. It should be replaced by if even == True: or if even:. The program runs and displays It is even! The program runs, but displays nothing.

The program has a syntax error in line 2 if even = True is not a correct condition. It should be replaced by if even == True: or if even:.

T/F Python syntax is case-sensitive.

True

T/F. What is the value of the following expression? True or True and False

True

What is assigned to the variable result given the statement below with the following assumptions: x = 10 and y = 7. result = x >= y 7 False 10 True x >= 7

True

What is assigned to the variable result given the statement below with the following assumptions: x = 10, y = 7. result = x >= y 7 True False 10 None of these

True

What is the result of the following Boolean expression, if x equals 5, y equals 3, and z equals 8? x < y or z > x True 8 5 False

True

A Boolean variable can reference one of two values: ________. yes or no T or F True or False Y or N

True or False

CPU

____ is the brain of a computer

The symbols >, <, and == are all ________ operators. comparison ternary conditional mathematical

comparison

What function do you use to read a string? -input("Enter your name: ") -eval(enter("Enter your name: ")) -enter("Enter your name: ") -You Answered eval(input("Enter your name: "))

eval(input('Enter your name: "))

To format a number x to 3 digits after the decimal point, use _______. format("0.3f", x) format(x, "0.3f") format("3f", x) format(x, "3f")

format(x, "0.3f")

Which is the following code displays the area of a circle if the radius is positive. if radius >= 0: print(radius * radius *3.14159) if radius <= 0: print(radius * radius *3.14159) if radius > 0: print(radius * radius *3.14159) if radius != 0: print(radius * radius*3.14159)

if radius > 0: print(radius * radius *3.14159)

Which of the following code displays the area of a circle if the radius is positive. if radius <= 0: print(radius*radius*3.14159) if radius > 0: print(radius*radius*3.14159) if radius >= 0: print(radius*radius*3.14159) if radius != 0: print(radius*radius*3.14159)

if radius > 0: print(radius*radius*3.14159)

Which of the following is the correct if clause to determine whether y is in the range 10 through 50? if 10 < y or y > 50 if 10 > y and y < 50 if y > 10 and y < 50 if y > 10 or y < 50

if y > 10 and y < 50

What function do you use to read a string? input("Enter your name: ") eval(enter("Enter your name: ")) enter("Enter your name: ") eval(input("Enter your name: "))

input("Enter your name: ")

This built-in function can be used to read input that has been typed on the keyboard. -get_input() -Correct! input() -keyboard() -read_input()

input()

The following code displays ________. temperature = 50 if (temperature >= 100: print("too hot") elif temperature <= 40: print("too cold") else: print("just right") too cold too hot too cold just right too hot just right

just right

Words that have a special meaning in a programming language are called______.

keywords

Which of the following is a valid identifier? 8+9 9x max_radius $343

max_radius

Which of the following is a valid identifier? -print -(red) -Correct! mile1 -"red"

mile1

Suppose x =1, y = -1, and z = 1. What will be displayed by the following statement? if x > 0: if y > 0: print("x > 0 and y >0") elif z > 0: print("x < 0 and z > 0") nothing displayed x < 0 and z < 0 x > 0 and y > 0 x < 0 and z > 0

nothing displayed

When using the _____ operator, one or both sub-expressions must be true for the compound expression to be true. and not maybe or

or

A (single lined )comment in Python is indicated by a____.

pound sign #

The Python reserved word for performing output to the screen is

print

What symbol is used to mark the beginning and end of a string?

quotation

To generate a random integer between 0 and 5, use __________. andom.randrange(0, 5) random.randrange(0, 6) random.randint(0, 6) random.randint(0, 5)

random.randint(0, 5)

Which of the following statements is correct? s = "Chapter " + 1 s = "Chapter " + str(1) s = "Chapter " + String(1) s = 1 + "Chapter"

s = "Chapter " + str(1)

A ______ is a sequence of characters. -string -math expression -character collection -text block

string

The rules that govern that correct order and usage of the elements of a language are called______ of the language.

syntax

What will be displayed by the following code? x = x + 2.5 print(x) 1 0 Correct! The statements are illegal. 2.5

the statements are illegal

What will be displayed by the following code? x = x + 2.5 print(x) The statements are illegal. 1 0 2.5

the statements are illegal

Suppose a program executes the following statement. value = eval(input("Enter a number: ")) In response to the prompt, the user types 5 + 5. What is the result? value contains 5 value contains 10 the program crashes value contains 55

value contains 10

A _______ is a name that references a value in the computer's memory. RAM slot register flowchart Correct! variable

variable

What is the output of the following code? x = 0 if x < 0 : x = x + 1 print (" x is", x) x is 3 x is 1 x is 0 x is 2

x is 0

What does the following expression mean? x <= y x is greater than y x is less than y x is less than or equal to y x is greater than or equal to y

x is less than or equal to y

Assume x = 4 and y = 5, which of the following is true? y == 4 x != 4 x != 5 x == 5

x!=5

Which of the following statement is true? A. Python 3 is a newer version, but it is backward compatible with Python 2. B. Python 3 is a newer version, but it is not backward compatible with Python 2. C. A Python 2 program can always run on a Python 3 interpreter. D. A Python 3 program can always run on a Python 2 interpreter.

B. Python 3 is a newer version, but it is not backward compatible with Python 2.

What will be displayed by the following code? x = 1 x = 2*x + 1 print(x) A. 1 B. 2 C. 3 D. 3

D. 3

What would Python print as a result of this interaction: >>> print(2 + 3) A. 2 + 3 = 5 B. 2 + 3 C. Error D. 5

D. 5

T/F. If you print a variable that has not been assigned a value, the number 0 will be displayed.

False

T/F. In Python, math expressions are evaluated from left to right, no matter what the operators are.

False

T/F. In Python, variable names can begin with either a letter or a number.

False

T/F. The if statement causes one or more statements to execute only when a Boolean expression is false.

False

The Python numeric type for representing numbers containing fractional values is float decimal int real

Float

Python is an example of a(n):

High-level programming language

The expression "Good " + 1 + 2 +3 evaluates to ______. Good123 Good6 Illegal expression Good 123

Illegal expression


Set pelajaran terkait

Unit 3 - BIO 223 (Chapter 10-11)

View Set

Pharm: Respiratory, endocrine, antimicrobial NCLEX style questions

View Set

Real Estate Principles and Practices

View Set

History of Rock Ch 7 Key Figures

View Set

Business Law Chapter 12 Questions

View Set

Chapter 6- Life insurance Underwriting and Policy issue

View Set