100k views
2 votes
Write a program that creates a list called temperatures then adds five temperatures that are input by the user. The temperatures should be added as ints, not as strings. Then, print the list.

Sample Run
Enter a temperature: 45
Enter a temperature: 67
Enter a temperature: 89
Enter a temperature: 47
Enter a temperature: 89
[45, 67, 89, 47, 89]

1 Answer

5 votes

Answer:

temperatures = []

i = 0

while i < 5:

try:

t = int(input('Enter a temperature: '))

temperatures.append(t)

i += 1

except ValueError:

print('Enter a number')

print(temperatures

User Ku
by
8.4k points