Elementary Programming Flashcards
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