-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.py
More file actions
29 lines (20 loc) · 761 Bytes
/
Copy pathtask2.py
File metadata and controls
29 lines (20 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#Write a program that asks the user to enter numbers until they input an empty string to quit.
#At the end, the program prints out the five greatest numbers sorted in descending order.
#Hint: You can reverse the order of sorted list items by using the sort method with the
#reverse=True argument.
import math
largest_number = -math.inf
smallest_number = math.inf
line = input("enter number:")
x = float(line)
list_of_numbers = []
while line != "":
x = float(line)
line = input("enter number:")
list_of_numbers = list_of_numbers + [x]
if len(list_of_numbers) < 6:
list_of_numbers.sort(reverse=True)
if len(list_of_numbers) >= 6:
list_of_numbers.sort(reverse=True)
list_of_numbers.pop(5)
print(list_of_numbers)