Module 5 Flashcards

1
Q
item = 25 

if item > 10:
    magnitude = 'Between 10 and 20'
elif item > 20:
    magnitude = 'Greater than 20'
else:
    magnitude = '10 or less'

magnitude

output ?

A

Between 10 and 20

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

if item > 20:
    magnitude = 'Greater than 20'
elif item > 10:
    magnitude = 'Between 10 and 20'
else:
    magnitude = '10 or less'

magnitude

output ?

A

‘Greater than 20’

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

for i in range(5):
print(i)

	output
A

0
1
2
3
4

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

for i in range(50, 101, 10):
print(i)

A

50
60
70
80
90
100

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

for i in range(0.5,1.0,0.1):
print(i)

A

TypeError: ‘float’ object cannot be interpreted as an integer.

Detailed traceback:
File “<string>", line 1, in <module></module></string>

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

for i in range(4):
print(i)

A

0
1
2
3

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

cereals = {‘Special K’: 4, ‘Lucky Charms’: 7, ‘Cheerios’: 2, ‘Wheaties’: 3}

for cereal, stock in cereals.items():
print( cereal + “ has “ + str(stock) + “ available”)

A

Special K has 4 available
Lucky Charms has 7 available
Cheerios has 2 available
Wheaties has 3 available

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

numbers = [2, 3, 5]

word_length = {number : number ** 2 for number in numbers}
word_length

A

{2: 4, 3: 9, 5: 25}

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

item_list = [25, 13, 21, 8, 17, 11, 4]

for item in item_list:
if item > 20:
magnitude = ‘greater than 20’
elif item > 10:
magnitude = ‘between 10 and 20’
else:
magnitude = ‘10 or less’
break

print(magnitude)
A

greater than 20
between 10 and 20
greater than 20

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

number_over_20 += item

is the same as ?

A

number_over_20 = number_over_20 + item

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