Advertisement
Guest User

python

a guest
Oct 10th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. #LIST SORTING PROGRAM
  2.  
  3. #Create an endless while loop to continuously run the program
  4. while True:
  5. try:
  6.  
  7. #Print the title of the program
  8. print('\n-------------- List Sorting program -------------- \n')
  9.  
  10.  
  11. #define a list containing 10 hard coded games
  12.  
  13. #1 #2 #3 #4 #5 #6 #7 #8 #9 #10
  14. Games = [ 'Rust' , 'God of War' , 'Far Cry 5' , 'Spider-Man' , 'Dragon BallZ' , 'Sea of Thieves' , 'Tomb-Raider' , 'Into the Breach' , 'Red Dead Redemption' , 'Celeste' ]
  15.  
  16. #Prints a message to the screen
  17. print('This list contains : \n')
  18.  
  19. #For-loop to iterate through the orginal list and print the list
  20. for games in Games:
  21. print(games)
  22.  
  23.  
  24. #Ask user for input on how they would like to sort the list
  25. 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 ')
  26.  
  27. #User decides what number they pick and inputs it here
  28. Choice = int(input(' Enter choice : '))
  29.  
  30. #Prints a new line
  31. print('\n')
  32.  
  33. #If the user choice is 1, the original list will be printed using a for loop
  34. if Choice == 1:
  35. print('#### Original List ####')
  36. for games in Games:
  37. print(games)
  38.  
  39. #If user choice is 2, the Desending list will be printed using a for loop
  40. elif Choice == 2:
  41. print('#### Desending List ####')
  42. Games.sort(reverse=True)
  43. for games in Games:
  44. print(games)
  45.  
  46. #If user choice is 3, the alphabetical list will be printed using a for loop
  47. elif Choice == 3:
  48. print('#### Alphabetical List ####')
  49. Games.sort(reverse=False)
  50. for games in Games:
  51. print(games)
  52.  
  53. #If user choice is 4, the alphabetical list will be printed using a for loop
  54. elif Choice == 4:
  55. print('#### Reversed List ####')
  56. Games.reverse()
  57. for games in Games:
  58. print(games)
  59.  
  60. #If user choice is 5, an error will occur
  61. elif Choice >= 5:
  62. print(' You cannot use' , Choice)
  63.  
  64. #Else if the input is not excepted or manually caught the program will pass
  65. else:
  66. pass
  67.  
  68. except:
  69. print(' Sorry that is not valid, please try again.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement