Elementary Programming Flashcards

1
Q

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.

A

E. The program will have a runtime error on the input.

Hint: You have to enter each number on a separate line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

identifiers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

Valid identifiers: miles, Test, apps, x, y, radius
Invalid identifiers: a+b, b-a, 4#R, $4, #44, if, elif
Keywords: if, elif

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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
A

D. 3.5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is wrong in the following statement?

2 = a

A

You should write a = 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the result of 25 / 4? How would you rewrite the expression if you wished the result to be an integer number?

A

25 / 4 is 6.25. If you want the result to be an integer, use 25 // 4, which evaluates to 6.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
What is the result of 45 / 4?
 A. 10
 B. 11
 C. 11.25
 D. 12
A

C. 11.25

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
2 ** 3 evaluates to \_\_\_\_\_\_\_\_\_\_.
 A. 9
 B. 8
 C. 9.0
 D. 8.0
A

B. 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
What is the result of 45 // 4?
 A. 10
 B. 11
 C. 11.25
 D. 12
A

B. 11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
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
A

Which of the following expressions will yield 0.5?
A. 1 / 2
B. 1.0 / 2
E. 1 / 2.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
2 * 3 ** 2 evaluates to \_\_\_\_\_\_\_\_\_\_.
 A. 36
 B. 18
 C. 12
 D. 81
A

B. 18

Hint: The ** operator is performed before the * operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
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
A

B. operands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The % operator, known as ______ or ______ operator, yields the _______ after _______.

A

The % operator, known as remainder or modulo operator, yields the remainder after division.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If today is Tuesday, what day of the week will it be in 100 days?

A

(2 + 100) % 7 = 4. So it is Thursday

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
Which of the following expression results in a value 1?
 A. 2 % 1
 B. 15 % 4
 C. 25 % 5
 D. 37 % 6
A

D. 37 % 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
25 % 1 is \_\_\_\_\_
 A. 1
 B. 2
 C. 3
 D. 4
 E. 0
A

E. 0

17
Q
24 % 5 is \_\_\_\_\_
 A. 1
 B. 2
 C. 3
 D. 4
 E. 0
A

D. 4

18
Q
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
A
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
19
Q
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
A

All of these expressions are equivalent to 0.025.

20
Q

If a number is too large to be stored in memory, it _____________.

A

causes overflow

21
Q
What is the result of evaluating 2 + 2 ** 3 / 2?
 A. 4
 B. 6
 C. 4.0
 D. 6.0
A

D. 6.0

Hint: In Python 3, the result of the / operator is a float value.

22
Q
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
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)
23
Q

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
A

E. 7

Hint: i and j are 1, (1 + 1 * 5) add to i. i becomes 7.

24
Q

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

A. x is 1.

Hint: x is 2 and y is 1. x // (1 + 1) is 1. So, the answer is a.

25
Q

Which of the following statements are the same?

(A) x -= x + 4
(B) x = x + 4 - x
(C) x = x - (x + 4)

A. (A) and (B) are the same
B. (A) and (C) are the same
C. (B) and (C) are the same
D. (A), (B), and (C) are the same

A

B. (A) and (C) are the same

26
Q

What does time.time() return?

A

time.time() returns the seconds with millisecond precision since the UNIX epoch.

27
Q

How do you obtain the seconds from the returned value for time.time()?

A

To obtain seconds from the return value of time.time(), use int(time.time()).

28
Q

The time.time() returns ________________ .

A

the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).

29
Q

Requirement Specification is

A

a formal process that seeks to understand the problem that the software will address and to document in detail what the software system needs to do.

30
Q

Analysis seeks to

A

analyze the data flow and to identify the system’s input and output.

31
Q

Design is to

A

design a process for obtaining the output from the input.

32
Q

Implementation involves

A

translating the system design into programs.

33
Q

Testing ensures that

A

the code meets the requirements specification and weeds out bugs.

34
Q

Deployment makes the______ available for use.

A

software

35
Q

Maintenance is concerned with ______ and _______ the product.

A

updating and improving

36
Q

The essence of system analysis and design is ____, _____, and ______. This is called _____.

A

The essence of system analysis and design is input, process, and output. This is called IPO.