Block 2 Part 2 - Algorithm and Patterns 2 Flashcards

1
Q

Inspect the following code:

for position in range(0, len(input_list)):
  input_value = input_list[position]

If the item positions are not needed for anything else, we can iterate directly over the items of a list, using an ‘abbreviation’ of the above.

Write the abbreviation.

A

for input_value in input_list:
  # do something with input_value

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

Loop variables

1) In this code, what is the loop
variable(aka Index variable)?

2) What is the command to append each
converted value to the fahrenheit_values
list?

celsius_values = [28, 33, 29, 32, 27]
fahrenheit_values = []

for temp in celsius_values:
fahrenheit = temp * 1.8 + 32
fahrenheit_values.append(fahrenheit)

print(‘The temperatures in Fahrenheit are’, fahrenheit_values)

A

1) temp

2) .append

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

What is the null value called in Python?

A

None (n with upper-case)

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