sort number program in python code example
Example 1: a program that asks for the user's input of a list of numbers and sort it in reverse in python
Enter a number:2
Do you want to input more:yes
Enter another number:3
Do you want to input more:yes
Enter another number:4
Do you want to input more:no
[4,3,2]
Example 2: a program that asks for the user's input of a list of numbers and sort it in reverse in python
try:
raw_input
except NameError:
raw_input = input
my_list = [int(raw_input("Enter a number: "))]
while True:
b = raw_input("Do you want to input more: ")
if b == 'yes':
my_list.append(int(raw_input("Enter another number:")))
elif b == 'no':
my_list.sort(reverse=True)
print(my_list)
break