[6 pts]
If x
is the integer 50,
what is the value of each of the following Python
expressions?
a. x % 8
b. (x // 15) * 15
c. x + x ** 2
[6 pts]
List the values of a
, b
, and c
following the
execution of the below fragment.
a = 10
b = 20
c = 30
a = b
c = a
b = 5
[8 pts]
Recall from physics that if you drop an object, after t seconds
it will have fallen 16 t² feet. Suppose the variable ball
has been set up holding a ball's initial height, measured in feet from the
ground. Create a variable splat
holding the number of seconds it
will take between when the ball is released and when it hits the
ground.
[6 pts]
If s
is the string “warrior” (no quotes),
what is the value of each of the following Python expressions?
a. s[4]
b. s[1:5]
c. 's' + s
[8 pts] What is the output of the following program?
a = '0'
for i in range(5):
a = a + 'i'
print(a)
[12 pts]
Using a for
loop, write a program that computes and
displays
[6 pts]
What will be in the list nums
following execution of the
below code?
nums = [1, 1]
for i in range(4):
nums = nums + [i]
[6 pts]
If nums
is [11, 7, 5, 3, 2], what is the value of each
of the following expressions?
a. nums[1] + nums[-1]
b. sorted(nums[1:4])
c. nums[min(nums)]
[10 pts]
Tabulate how the variables i
, x
, and y
change
while executing the below program fragment.
data = [2, 3, 5, 7, 11, 13]
y = 0
for i in range(5):
x = data[i] % 4
if x >= y:
y = y + x
[12 pts] The below program reads 50 integers from the user. Modify the program so that after reading the fiftieth integer, it displays the sum of all those integers that are less than 100. For example, if the user enters 200, 59, 99, 105, and 10, then enters 150 forty-five times, the output should be 168 (from 59 + 99 + 10)
for index in range(50):
num = int(input())
a. | x % 8 | is | 2 |
b. | (x // 15) * 15 | is | 45 |
c. | x + x ** 2 | is | 2,550 |
a | = | 20 |
b | = | 5 |
c | = | 20 |
splat = (ball / 16) ** 0.5
a. | s[4] | is | i |
b. | s[1:5] | is | arri |
c. | 's' + s | is | swarrior |
0i
0ii
0iii
0iiii
0iiiii
total = 0
for i in range(1, 1001):
total = total + 1 / (i ** 2)
print(total)
a. | nums[1] + nums[-1] | is | 9 |
b. | sorted(nums[1:4]) | is | [3, 5, 7] |
c. | nums[min(nums)] | is | 5 |
i : |
0 | 1 | 2 | 3 | 4 | ||||||||
x : |
2 | 3 | 1 | 3 | 3 | ||||||||
y : |
0 | 2 | 5 |
total = 0
for index in range(50):
num = int(input())
if num < 100:
total = total + num
print(total)