Block 2 Part 2 - Algorithm and Patterns 2 Flashcards
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.
for input_value in input_list:
# do something with input_value
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)
1) temp
2) .append
What is the null value called in Python?
None (n with upper-case)