CS Exam 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

6.7 Which of the following should be defined as a None function? A. Write a function that prints integers from 1 to 100. B. Write a function that returns a random integer from 1 to 100. C. Write a function that checks whether a number is from 1 to 100. D. Write a function that converts an uppercase letter to lowercase.

A

True is:

A boolean literal Python Keyword

4.26 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

AC

4.34 Which of the following statements are True? A. (x > 0 and x < 10) is same as (x > 0 and x < 10) B. (x > 0 or x < 10) is same as (0 < x < 10) C. (x > 0 or x < 10 and y < 0) is same as (x > 0 or (x < 10 and y < 0)) D. (x > 0 or x < 10 and y < 0) is same as ((x > 0 or x < 10) and y < 0)

AC

5.3 Analyze the following code. 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

AE

4.15 Suppose income is 4001, what will be displayed by f 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

B

5.22 What is sum after the following loop terminates? sum = 0 item = 0 while item < 5: item += 1 sum += item if sum > 4: break print(sum) A. 5 B. 6 C. 7 D. 8

B

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 if even:. C. The program runs, but displays nothing. D. The program runs and displays It is even!.

B

4.31 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

5.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

.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

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

A function with no return statement returns ______.

None

If a function does not return a value, by default, it returns ___________.

None

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

5.18 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

Suppose isPrime is a boolean variable, which of the following is the correct and best statement for testing if isPrime is true.

if isPrime:

range arguments must be:

integers

Arguments to functions always appear within

parentheses

When you invoke a function with a parameter, the value of the argument is passed to the parameter. This is referred to as _________.

pass by value

2 ways to produce a random int betweeen 0 and 5

random.randint(0,5) random.randrange(0,6)

What function immediately terminates the program

sys.exit()

random.randint(0,1) returns

0 or 1


Conjuntos de estudio relacionados

Current Issues & Trends (from powerpoints)

View Set

Ch. 14, Nationalism and the Spread of Democracy, 1790-1814

View Set

Voting and Political Participation (17) - American Government

View Set

Developmental Psych Chapter 2: Biological Beginnings

View Set

Chapter 3: Evaluating a Company's External Environment

View Set