Elementary Programming Flashcards
(36 cards)
If you enter 1 2 3 in one line, when you run this program, what will happen?
print(“Enter three numbers: “)
number1 = int(input())
number2 = int(input())
number3 = int(input())
# Compute average average = (number1 + number2 + number3) / 3
# Display result print(average)
A. The program runs correctly and displays 1.0
B. The program runs correctly and displays 2.0
C. The program runs correctly and displays 3.0
D. The program runs correctly and displays 4.0
E. The program will have a runtime error on the input.
E. The program will have a runtime error on the input.
Hint: You have to enter each number on a separate line.
number1, number2, and number3, average, input, float, and print are the names of things that appear in the program. In programming terminology, such names are called _______.
identifiers.
Which of the following identifiers are valid? Which are Python keywords?
miles, Test, a+b, b-a, 4#R, $4, #44, apps
if, elif, x, y, radius
Valid identifiers: miles, Test, apps, x, y, radius
Invalid identifiers: a+b, b-a, 4#R, $4, #44, if, elif
Keywords: if, elif
What will be displayed by the following code?
x = 1
x = x + 2.5
print(x)
A. 1 B. 2 C. 3 D. 3.5 E. The statements are illegal
D. 3.5
What is wrong in the following statement?
2 = a
You should write a = 2
What is the result of 25 / 4? How would you rewrite the expression if you wished the result to be an integer number?
25 / 4 is 6.25. If you want the result to be an integer, use 25 // 4, which evaluates to 6.
What is the result of 45 / 4? A. 10 B. 11 C. 11.25 D. 12
C. 11.25
2 ** 3 evaluates to \_\_\_\_\_\_\_\_\_\_. A. 9 B. 8 C. 9.0 D. 8.0
B. 8
What is the result of 45 // 4? A. 10 B. 11 C. 11.25 D. 12
B. 11
Which of the following expressions will yield 0.5? A. 1 / 2 B. 1.0 / 2 C. 1 // 2 D. 1.0 // 2 E. 1 / 2.0
Which of the following expressions will yield 0.5?
A. 1 / 2
B. 1.0 / 2
E. 1 / 2.0
2 * 3 ** 2 evaluates to \_\_\_\_\_\_\_\_\_\_. A. 36 B. 18 C. 12 D. 81
B. 18
Hint: The ** operator is performed before the * operator.
In the expression 45 / 4, the values on the left and right of the / symbol are called \_\_\_\_. A. operators B. operands C. parameters D. arguments
B. operands
The % operator, known as ______ or ______ operator, yields the _______ after _______.
The % operator, known as remainder or modulo operator, yields the remainder after division.
If today is Tuesday, what day of the week will it be in 100 days?
(2 + 100) % 7 = 4. So it is Thursday
Which of the following expression results in a value 1? A. 2 % 1 B. 15 % 4 C. 25 % 5 D. 37 % 6
D. 37 % 6
25 % 1 is \_\_\_\_\_ A. 1 B. 2 C. 3 D. 4 E. 0
E. 0
24 % 5 is \_\_\_\_\_ A. 1 B. 2 C. 3 D. 4 E. 0
D. 4
42 / 5 42 // 5 42 % 5 40 % 5 1 % 2 2 % 1 45 + 4 * 4 - 2 45 + 43 % 5 * (23 * 3 % 2) 5 ** 2 5.1 ** 2
42 / 5 = 8.4 42 // 5 = 8 42 % 5 = 2 40 % 5 = 0 1 % 2 = 1 2 % 1 = 0 45 + 4 * 4 - 2 = 59 45 + 43 % 5 * (23 * 3 % 2) = 48 5 ** 2 = 25 5.1 ** 2 = 26.0099
Which of the following is equivalent to 0.025? A. 0.25E-1 B. 2.5e-2 C. 0.0025E1 D. 0.00025E2 E. 0.0025E+1
All of these expressions are equivalent to 0.025.
If a number is too large to be stored in memory, it _____________.
causes overflow
What is the result of evaluating 2 + 2 ** 3 / 2? A. 4 B. 6 C. 4.0 D. 6.0
D. 6.0
Hint: In Python 3, the result of the / operator is a float value.
Assume that a = 1, and that each expression is independent. What are the results of the following expressions? a += 4 a -= 4 a *= 4 a /= 4 a //= 4 a %= 4 a = 56 * a + 6
a += 4 (a is 5) a -= 4 (a is -3) a *= 4 (a is 4) a /= 4 (a is 0.25) a //= 4 (a is 0) a %= 4 (a is 1) a = 56 * a + 6 (a is 62)
What is the value of i printed?
j = i = 1 i += j + j * 5 print("What is i?", i) A. 0 B. 1 C. 5 D. 6 E. 7
E. 7
Hint: i and j are 1, (1 + 1 * 5) add to i. i becomes 7.
What is x after the following statements?
x = 2 y = 1 x //= y + 1 A. x is 1. B. x is 2. C. x is 3. D. x is 4.
A. x is 1.
Hint: x is 2 and y is 1. x // (1 + 1) is 1. So, the answer is a.