CSIT 104 - Midterm Review

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

To check whether a char variable ch is an uppercase letter, you write ___________. A. (ch >= 'A' and ch >= 'Z') B. (ch >= 'A' and ch <= 'Z') C. (ch >= 'A' or ch <= 'Z') D. ('A' <= ch <= 'Z')

B. (ch >= 'A' and ch <= 'Z') & D. ('A' <= ch <= 'Z')

The following loop displays _______________. for i in range(1, 11): print(i, end = " ") A. 1 2 3 4 5 6 7 8 9 B. 1 2 3 4 5 6 7 8 9 10 C. 1 2 3 4 5 D. 1 3 5 7 9 E. 2 4 6 8 10

B. 1 2 3 4 5 6 7 8 9 10

The "less than or equal to" comparison operator is __________. A. < B. <= C. =< D. << E. !=

B. <=

Suppose income is 4001, what will be displayed by the following code? if income > 3000: print("Income is greater than 3000") elif income > 4000: print("Income is greater than 4000") A. none B. Income is greater than 3000 C. Income is greater than 3000 followed by Income is greater than 4000 D. Income is greater than 4000 E. Income is greater than 4000 followed by Income is greater than 3000 Your answer is correct

B. Income is greater than 3000.

What will be displayed by the following code? isCorrect = Falseprint("Correct" if isCorrect else "Incorrect") A. Correct B. Incorrect C. nothing D. Correct Incorrect

B. Incorrect

Analyze the following code. even = False if even: print("It is even!") A. The code displays It is even! B. The code displays nothing. C. The code is wrong. You should replace if even: with if even == True: D. The code is wrong. You should replace if even: with if even = True:

B. The code displays nothing.

sum = 0 for d in range(0, 10, 0.1): sum += sum + d A. The program has a syntax error because the range function cannot have three arguments. B. The program has a syntax error because the arguments in the range must be integers. C. The program runs in an infinite loop. D. The program runs fine.

B. The program has a syntax error because the arguments in the range must be integers.

The __________ function immediately terminates the program. A. sys.terminate() B. sys.halt() C. sys.exit() D. sys.stop()

C. sys.exit()

Which of the following loops prints "Welcome to Python" 10 times? A: for count in range(1, 10): print("Welcome to Python") B: for count in range(0, 10): print("Welcome to Python") C: for count in range(1, 11): print("Welcome to Python") D: for count in range(1, 12): print("Welcome to Python") A. BD B. ABC C. AC D. BC E. AB

D. BC

What is y after the following statement is executed? x = 0 y = 10 if x > 0 else -10 A. -10 B. 0 C. 10 D. 20 E. Illegal expression

A. -10

How many times is the print statement executed? for i in range(10): for j in range(10): print(i * j) A. 100 B. 20 C. 10 D. 45

A. 100

What will be displayed by the following code? ch = 'F'if ch >= 'A' and ch <= 'Z':print(ch) A. F B. f C. nothing D. F f

A. F

What is the value of the following expression? True or True and False A. True B. False

A. True

Loop Continuation Condition

is a Boolean expression that controls the execution of the loop.

Infinite Loop

is a loop that runs forever due to an error in the code.

randint(a,b)

returns a random integer between a and b

The function range(5) returns a sequence ______________. A. 1, 2, 3, 4, 5 B. 0, 1, 2, 3, 4, 5 C. 1, 2, 3, 4 D. 0, 1, 2, 3, 4

D. 0, 1, 2, 3, 4

What is the output for y? y = 0 for i in range(0, 10, 2): y += i print(y) A. 9 B. 10 C. 11 D. 20

D. 20 (Because, you are going up by 2. The multiples of 2 from the range of 0-9 are 2, 4, 6 and 8. So, 2 + 4 + 6 + 8 = 20)

How many times is the print statement executed? for i in range(10): for j in range(i): print(i * j) A. 100 B. 20 C. 10 D. 45

D. 45

If you enter 5, what is the output of the following code? i = int(input("Enter an integer: ")) if i < 4: x = 1 else: x = -1 print(x) A. 4 B. 1 C. a syntax error is raised because x is not assigned. D. -1

D. -1

Analyze the following code: Code 1: if number % 2 == 0: even = True else: even = False Code 2: even = number % 2 == 0 A. Code 1 has compile errors. B. Code 2 has compile errors. C. Both Code 1 and Code 2 have compile errors. D. Both Code 1 and Code 2 are correct, but Code 2 is better.

D. Both Code 1 and Code 2 are correct, but Code 2 is better.

Assume x = 4 and y = 5, Which of the following is true? A. not (x == 4) B. x != 4 C. x == 5 D. x != 5

D. x != 5

What happens if you are entering an integer as 05?

It will be the same as entering 5.

How many times is the following loop executed? count = 5 while count > 1: count -= 3

Twice

Off-by-one

is an error in the program that causes the loop body to be executed one more or less time.

Iteration

is one time execution of the loop body.

Loop Body

is the part of the body that contains the statements to be repeated.

random()

returns a random float number between 0.0 and 1.0 (excluding 1.0)

rangeint(a,b)

returns a random integer between a and b - 1

Will the following program terminate? balance = 10 while True: if balance < 9: breakbalance = balance - 9 A. Yes B. No

A. Yes

The word True is ________. A. a Python keyword B. a Boolean literal C. same as value 1 D. same as value 0

A. a Python Keyword & B. a Boolean literal

To add 0.01 + 0.02 + ... + 1.00, what order should you use to add the numbers to get better accuracy? A. add 0.01, 0.02, ..., 1.00 in this order to a sum variable whose initial value is 0. B. add 1.00, 0.99, 0.98, ..., 0.02, 0.01 in this order to a sum variable whose initial value is 0.

A. add 0.01, 0.02, ..., 1.00 in this order to a sum variable whose initial value is 0.

Analyze the following code. Please select all that apply. count = 0 while count < 100: #Point A print("Welcome to Python!") count += 1 #Point B #Point C A. count < 100 is always True at Point A B. count < 100 is always True at Point B C. count < 100 is always False at Point B D. count < 100 is always True at Point C E. count < 100 is always False at Point C

A. count < 100 is always True at Point A & E. count < 100 is always False at Point C

Which of the following is equivalent to x != y? A. not (x == y) B. x > y and x < y C. x > y or x < y D. x >= y or x <= y

A. not (x == y) & C. x > y or x < y

To generate a random integer between 0 and 5, use ________________. A. random.randint(0, 5) B. random.randint(0, 6) C. random.randrange(0, 5) D. random.randrange(0, 6)

A. random.randint(0,5) & D. random.randrange(0,6)

Which of the following function is incorrect? A. range(0, 3.5) B. range(10, 4, -1) C. range(1, 3, 1) D. range(2.5, 4.5) E. range(1, 2.5, 4.5)

A. range(0, 3.5) & D. range(2.5, 4.5) & E. range(1, 2.5, 4.5) (This is because arguments in the range must be integers.)

Which of the Boolean expressions below is incorrect? A. True and 3 => 4 B. !(x > 0) and (x > 0) C. (x > 0) or (x < 0) D. (x != 0) or (x = 0) E. (-10 < x < 0)

A. True and 3 =>4 & B. !(x > 0) and (x > 0) & D. (x != 0) or (x = 0)

Analyze the following code: even = False if even = True: print("It is even!") A. The program has a syntax error in line 1 (even = False) B. 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 simply better using if even:. C. The program runs, but displays nothing. D. The program runs and displays It is even!.

B. 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 simply better using "if even:"

random.random() returns ____________. A. a float number i such that 0 < i < 1.0 B. a float number i such that 0 <= i < 1.0 C. a float number i such that 0 <= i <= 1.0 D. a float number i such that 0 < i < 2.0

B. a float number i such that 0 <= i < 1.0

Which of the following function returns a sequence 0, 1, 2, 3? Please select all that apply. A. range(0, 3) B. range(0, 4) C. range(3) D. range(4)

B. range(0, 4) & D. range(4)

Assume x = 14 and y = 15, Which of the following is true? A. x % 2 == 0 and y % 2 == 0 B. x % 2 == 0 and y % 2 == 1 C. x % 2 == 0 or y % 2 == 0 D. x % 2 != 0 and y % 2 != 0

B. x % 2 == 0 and y % 2 == 1 & C. x % 2 == 0 or y % 2 == 0

Assume x = 4 and y = 5, Which of the following is true? A. x < 5 and y < 5 B. x < 5 or y < 5 C. x > 5 and y > 5 D. x > 5 or y > 5

B. x < 5 or y < 5

Given |x| >= 4, Which of the following is true? A. x >= 4 and x <= -4 B. x >= 4 or x <= -4 C. x >= 4 and x < -4 D. x >= 4 or x <= -4

B. x >= 4 or x <= -4

What is the output of the following code? x = 0 if x < 4: x = x + 1 print("x is", x) A. x is 0 B. x is 1 C. x is 2 D. x is 3 E. x is 4

B. x is 1

The order of the precedence (from high to low) of the operators +, *, and, or is: A. and, or, *, + B. +, *, and, or C. *, +, and, or D. *, +, or, and E. or, and, *, +

C. *, +, and, or

random.randint(0, 1) returns ____________. A. 0 B. 1 C. 0 or 1 D. 2

C. 0 or 1

How many times will the following code print "Welcome to Python"? count = 0 while count < 10: print("Welcome to Python") count += 1 A. 8 B. 9 C. 10 D. 11 E. 0

C. 10

What will be displayed when the following code is executed? number = 6 while number > 0: number -= 3 print(number, end = ' ') A. 6 3 0 B. 6 3 C. 3 0 D. 3 0 -3 E. 0 -3

C. 3 0

What is the output for y? y = 0 for i in range(10, 1, -2): y += i print(y) A. 10 B. 40 C. 30 D. 20

C. 30 (Because, you are starting at 10, all the way to 1. The multiples of 2 from the range of 10-1 are 10, 8, 6, 4, 2, and 0. So, 10 + 8 + 6 + 4 + 2 + 0 = 30.)

The equal comparison operator is __________. A. <> B. != C. == D. =

C. ==

Suppose isPrime is a boolean variable, which of the following is the correct and best statement for testing if isPrime is true. A. if isPrime = True: B. if isPrime == True: C. if isPrime: D. if not isPrime = False: E. if not isPrime == False:

C. if isPrime: (This is because Python prefers conciseness, B would be right generally speaking, but you have to remember to maintain conciseness.)

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

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

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

C. just right

What is the output for y? y = 0 for i in range(0, 10): y += i print(y) A. 10 B. 11 C. 12 D. 13 E. 45

E. 45 (Because, you are doing 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, which is equal to 45.)

Which of the following operators are right-associative. A. * B. + C. % D. and E. =

E. =

Analyze the following code fragments that assign a boolean value to the variable even. Code 1: if number % 2 == 0: even = True else: even = False Code 2: even = True if number % 2 == 0 else False Code 3: even = number % 2 == 0 A. Code 2 has a syntax error, because you cannot have True and False literals in the conditional expression. B. Code 3 has a syntax error, because you attempt to assign number to even. C. All three are correct, but Code 1 is preferred. D. All three are correct, but Code 2 is preferred. E. All three are correct, but Code 3 is preferred.

E. All three are correct, but Code 3 is preferred.

How many times will the following code print "Welcome to Python"? count = 0 while count < 10: print("Welcome to Python") A. 8 B. 9 C. 10 D. 11 E. infinite number of times

E. infinite number of times

What is the output of the following code? x = 0 while x < 4: x = x + 1 print("x is", x) A. x is 0 B. x is 1 C. x is 2 D. x is 3 E. x is 4

E. x is 4

Given |x| <= 4, Which of the following is true? A. x <= 4 and x >= 4 B. x <= 4 and x > -4 C. x <= 4 and x >= -4 D. x <= 4 or x >= -4

C. x <= 4 and x >= -4


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

Human Nutrition 2210 Compiled Exam Keys

View Set

past simple and present perfect contrast

View Set

Microecon Chapter 16: Monopolistic Competition

View Set

Comptia 220-801 6.7.3 Practice Test Questions

View Set

CompTIA A+ 1002 (Core 2) - Sections 1.1 to 1.3

View Set

19: Essentials of Maternity, Newborn, and Women's Health Nursing 5th Edition Chapter 19

View Set