Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #LIST SORTING PROGRAM
- #Create an endless while loop to continuously run the program
- while True:
- try:
- #Print the title of the program
- print('\n-------------- List Sorting program -------------- \n')
- #define a list containing 10 hard coded games
- #1 #2 #3 #4 #5 #6 #7 #8 #9 #10
- Games = [ 'Rust' , 'God of War' , 'Far Cry 5' , 'Spider-Man' , 'Dragon BallZ' , 'Sea of Thieves' , 'Tomb-Raider' , 'Into the Breach' , 'Red Dead Redemption' , 'Celeste' ]
- #Prints a message to the screen
- print('This list contains : \n')
- #For-loop to iterate through the orginal list and print the list
- for games in Games:
- print(games)
- #Ask user for input on how they would like to sort the list
- print('\n enter how you would like to sort this list : \n\n 1 = Original list \n 2 = Desending list \n 3 = Alphabetical list \n 4 = Reversed list \n ')
- #User decides what number they pick and inputs it here
- Choice = int(input(' Enter choice : '))
- #Prints a new line
- print('\n')
- #If the user choice is 1, the original list will be printed using a for loop
- if Choice == 1:
- print('#### Original List ####')
- for games in Games:
- print(games)
- #If user choice is 2, the Desending list will be printed using a for loop
- elif Choice == 2:
- print('#### Desending List ####')
- Games.sort(reverse=True)
- for games in Games:
- print(games)
- #If user choice is 3, the alphabetical list will be printed using a for loop
- elif Choice == 3:
- print('#### Alphabetical List ####')
- Games.sort(reverse=False)
- for games in Games:
- print(games)
- #If user choice is 4, the alphabetical list will be printed using a for loop
- elif Choice == 4:
- print('#### Reversed List ####')
- Games.reverse()
- for games in Games:
- print(games)
- #If user choice is 5, an error will occur
- elif Choice >= 5:
- print(' You cannot use' , Choice)
- #Else if the input is not excepted or manually caught the program will pass
- else:
- pass
- except:
- print(' Sorry that is not valid, please try again.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement