Advertisement
okelikai

Computer Thing

Apr 27th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.84 KB | None | 0 0
  1. # class notes 4/26/16
  2. # https://trinket.io/python/c0d1d5470e
  3. import os
  4. import time
  5. import random
  6.  
  7. global admin_login_accounts
  8. global guest_login_accounts
  9. admin_login_accounts = ['admin']
  10. guest_login_accounts = ['guest']
  11.  
  12. def user_login(user_level):
  13. transaction_number_generator()
  14. inputted_name = raw_input("What is your username: \n")
  15. if inputted_name in admin_login_accounts:
  16. print "Access granted, welcome back admin. Access Code: %s" % transaction_number
  17. user_level = user_level+1
  18. admin_commands(user_level)
  19. elif inputted_name in guest_login_accounts:
  20. print "Access granted, welcome to the computer guest. Access Code: %s" % transaction_number
  21. guest_commands(user_level)
  22. else:
  23. print "Access Denied"
  24. user_login(0)
  25. return
  26.  
  27. def admin_commands(user_level):
  28. print """
  29. 1. User Settings
  30. 2. Games
  31. 3. Power Down/Log Out
  32. """
  33. admin_choice = raw_input("What would you like to run? \n")
  34. admin_choice=int(admin_choice)
  35. if admin_choice == 1:
  36. os.system('clear')
  37. user_settings(user_level)
  38. elif admin_choice == 2:
  39. os.system('clear')
  40. games(user_level)
  41. elif admin_choice == 3:
  42. os.system('clear')
  43. power_down_logout(user_level)
  44. else:
  45. print "Invalid Input"
  46. time.sleep(3)
  47. os.system('clear')
  48. admin_commands(user_level)
  49.  
  50. def guest_commands(user_level):
  51. print """
  52. 1. Games
  53. 2. Power Down
  54. 3. Return to Menu
  55. """
  56. guest_choice = raw_input("What would you like to run? \n")
  57. guest_choice=int(guest_choice)
  58. if guest_choice == 1:
  59. os.system('clear')
  60. games(user_level)
  61. elif guest_choice == 2:
  62. os.system('clear')
  63. power_down_logout(user_level)
  64. else:
  65. print "Invalid Input"
  66. time.sleep(3)
  67. os.system('clear')
  68. guest_commands(user_level)
  69.  
  70. def user_settings(user_level):
  71. print """
  72. 1. Create Admin
  73. 2. Create Guest
  74. 3. Return to Menu
  75. """
  76. user_settings_choice = raw_input("What would you like to run? \n")
  77. user_settings_choice = int(user_settings_choice)
  78. if user_settings_choice == 1:
  79. os.system('clear')
  80. create_admin_account(user_level)
  81. elif user_settings_choice == 2:
  82. os.system('clear')
  83. create_guest_account(user_level)
  84. elif user_settings_choice == 3:
  85. user_level_check(user_level)
  86.  
  87. def games(user_level):
  88. print """
  89. 1. Random Number Guesser
  90. 2. Commons Lunch Generator
  91. 3. Return to Menu
  92. """
  93. games_choice = raw_input("What would you like to run? \n")
  94. games_choice = int(games_choice)
  95. if games_choice == 1:
  96. os.system('clear')
  97. random_number_game(user_level)
  98. elif games_choice == 2:
  99. os.system('clear')
  100. food_menu(user_level)
  101. elif games_choice == 3:
  102. user_level_check(user_level)
  103.  
  104. def power_down_logout(user_level):
  105. print """
  106. 1. Log Out
  107. 2. Power Down
  108. 3. Return to Menu
  109. """
  110. power_logout_choice = raw_input("What would you like to run? \n")
  111. power_logout_choice = int(power_logout_choice)
  112. if power_logout_choice == 1:
  113. os.system('clear')
  114. user_login(0)
  115. elif power_logout_choice == 2:
  116. time.sleep(1)
  117. print "Shut down in \n3..."
  118. time.sleep(1)
  119. print "2..."
  120. time.sleep(1)
  121. print "1..."
  122. time.sleep(1)
  123. os.system('clear')
  124. return
  125. elif power_logout_choice == 3:
  126. user_level_check(user_level)
  127.  
  128. def transaction_number_generator():
  129. global transaction_number # can be acessed in other
  130. sequence_letter_one = random.choice(['a','b','c','d','e','f','g'])
  131. sequence_letter_two = random.choice(['a','b','c','d','e','f','g'])
  132. sequence_letter_three = random.choice(['a','b','c','d','e','f','g'])
  133. sequence_number_one = random.choice(['1','2','3','4','5','6','7','8','9','0'])
  134. sequence_number_two = random.choice(['1','2','3','4','5','6','7','8','9','0'])
  135. transaction_number = "%s%s%s%s%s" % (sequence_letter_one,sequence_letter_two,sequence_number_one,sequence_letter_three,sequence_number_two)
  136.  
  137. def create_admin_account(user_level):
  138. new_admin_name = raw_input("Enter the new login:\n")
  139. admin_login_accounts.append(new_admin_name)
  140. "%s is now an admin login."
  141. os.system('clear')
  142. admin_commands(user_level)
  143.  
  144. def create_guest_account(user_level):
  145. new_guest_name = raw_input("Enter the new login:\n")
  146. guest_login_accounts.append(new_guest_name)
  147. "%s is now a guest login."
  148. os.system('clear')
  149. admin_commands(user_level)
  150.  
  151. def random_number_game(user_level):
  152. import random # import random
  153. global random_number
  154. random_number = random.choice(range(1, 51)) # Generating random number
  155.  
  156. def name_input():
  157. global user_name # so name can be used in other function
  158. user_name = raw_input("What is your name? \n")
  159. print "Okay %s, let's play!\n" % user_name
  160.  
  161. def number_check(guess_counter, user_level):
  162. transaction_number_generator()
  163. user_guess=raw_input("Pick a number between 1 and 50 \n") # user input for guess
  164. user_guess=int(user_guess)
  165. while guess_counter <= 7:
  166. if 50 >= user_guess > random_number:
  167. print "Try again, the number you picked is too high. Guess %s of 8. \nAccess Token: %s\n" % (guess_counter,transaction_number) # number too high
  168. number_check(guess_counter+1, user_level)
  169. return
  170. elif 0 < user_guess < random_number:
  171. print "Try again, the number you picked is too low. Guess %s of 8. \nAccess Token: %s\n" % (guess_counter,transaction_number) # number too low
  172. number_check(guess_counter+1, user_level)
  173. return
  174. elif user_guess >= 51: # dodoesnt consume guess for invalid answer
  175. print "That's not an answer! The number is less than or equal to 50!\nAccess Token: %s\n" % transaction_number
  176. number_check(guess_counter, user_level)
  177. return
  178. elif user_guess <= 0: # "
  179. print "That's not an answer! The number is greater than or equal to 1!\nAccess Token: %s\n" % transaction_number
  180. number_check(guess_counter, user_level)
  181. return
  182. elif user_guess == random_number:
  183. print 'You Win %s! You got it in %s guesses! \nAccess Token: %s' % (user_name, guess_counter, transaction_number) # correct
  184. user_level_check(user_level)
  185. return
  186. else: # for the instance of running out of guesses
  187. if 50 >= user_guess > random_number:
  188. print "Guess 8 of 8, you lose! The number you picked is too high, the correct number is %s. Play again sometime %s! \nAccess Token: %s\n" % (random_number,user_name,transaction_number)
  189. user_level_check(user_level)
  190. elif 0 < user_guess < random_number:
  191. print "Guess 8 of 8, you lose! The number you picked is too low, the correct number is %s. Play again sometime %s! \nAccess Token: %s\n" % (random_number,user_name,transaction_number)
  192. user_level_check(user_level)
  193. elif user_guess == random_number:
  194. print "You Win %s! You got it in %s guesses! \nAccess Token: %s" % (user_name, guess_counter, transaction_number) # correct
  195. user_level_check(user_level)
  196. elif user_guess >= 51: # dodoesnt consume guess for invalid answer
  197. print "That's not an answer! The number is less than or equal to 50!\nAccess Token: %s\n" % transaction_number
  198. number_check(guess_counter, user_level)
  199. return
  200. elif user_guess <= 0: # "
  201. print "That's not an answer! The number is greater than or equal to 1!\nAccess Token: %s\n" % transaction_number
  202. number_check(guess_counter, user_level)
  203. return
  204. name_input() # Calling function for user to input name
  205. number_check(1, user_level) # using 0 to have 8 guesses, to have less change number to be 8-inputted number = guesses
  206.  
  207. def food_menu(user_level):
  208. print (48*'-')
  209. print "What would you like to eat in the commons today?"
  210. print (48*'-')
  211. print "\t\t F O O D - M E N U"
  212. print (48*'-')
  213.  
  214. import random # importing the module
  215.  
  216. def food(random_food_one, random_food_two, random_food_three, random_food_four): # function for displaying the food
  217. print "1. %s" % random_food_one
  218. print "2. %s" % random_food_two
  219. print "3. %s" % random_food_three
  220. print "4. %s" % random_food_four
  221. def drink(random_drink_one, random_drink_two, random_drink_three, random_drink_four): # function for displaying the drink
  222. print "1. %s" % random_drink_one
  223. print "2. %s" % random_drink_two
  224. print "3. %s" % random_drink_three
  225. print "4. %s" % random_drink_four
  226. def snack(random_snack_one, random_snack_two, random_snack_three, random_snack_four): # function for displaying the snack
  227. print "1. %s" % random_snack_one
  228. print "2. %s" % random_snack_two
  229. print "3. %s" % random_snack_three
  230. print "4. %s" % random_snack_four
  231.  
  232. # making the randomizer for foods
  233. random_food_choice_one = random.choice(["BLT","Bacon-egg and cheese","Grilled-Cheese","Hot-dog","Burger","French-Fries","Rice","Bagel","Grilled-Fish"])
  234. random_food_choice_two = random.choice(["BLT","Bacon-egg and cheese","Grilled-Cheese","Hot-dog","Burger","French-Fries","Rice","Bagel","Grilled-Fish"])
  235. random_food_choice_three = random.choice(["BLT","Bacon-egg and cheese","Grilled-Cheese","Hot-dog","Burger","French-Fries","Rice","Bagel","Grilled-Fish"])
  236. random_food_choice_four = random.choice(["BLT","Bacon-egg and cheese","Grilled-Cheese","Hot-dog","Burger","French-Fries","Rice","Bagel","Grilled-Fish"])
  237. # making the randomizer for drinks
  238. random_drink_choice_one = random.choice(["Pepsi","Sprite","Coke","Aloe drink","Sunkist","Ginger-Ale","Lemonade","Naked-Smoothie"])
  239. random_drink_choice_two = random.choice(["Pepsi","Sprite","Coke","Aloe drink","Sunkist","Ginger-Ale","Lemonade","Naked-Smoothie"])
  240. random_drink_choice_three = random.choice(["Pepsi","Sprite","Coke","Aloe drink","Sunkist","Ginger-Ale","Lemonade","Naked-Smoothie"])
  241. random_drink_choice_four = random.choice(["Pepsi","Sprite","Coke","Aloe drink","Sunkist","Ginger-Ale","Lemonade","Naked-Smoothie"])
  242. # making the randomizer for snacks
  243. random_snack_choice_one = random.choice(["Chips", "Nerds", "Churro","Cookie","Kit-Kat","Muffin","Snickers","Chocolate","Brownie"])
  244. random_snack_choice_two = random.choice(["Chips", "Nerds", "Churro","Cookie","Kit-Kat","Muffin","Snickers","Chocolate","Brownie"])
  245. random_snack_choice_three = random.choice(["Chips", "Nerds", "Churro","Cookie","Kit-Kat","Muffin","Snickers","Chocolate","Brownie"])
  246. random_snack_choice_four = random.choice(["Chips", "Nerds", "Churro","Cookie","Kit-Kat","Muffin","Snickers","Chocolate","Brownie"])
  247.  
  248. food(random_food_choice_one, random_food_choice_two, random_food_choice_three, random_food_choice_four) # calling the food
  249. food_choice = raw_input("What food would you like? [1-4]") # user input food choice (1-4) which is then sent to if/elif below
  250. drink(random_drink_choice_one, random_drink_choice_two, random_drink_choice_three, random_drink_choice_four) # calling the drink
  251. drink_choice = raw_input("What drink would you like? [1-4]")
  252. snack(random_snack_choice_one, random_snack_choice_two, random_snack_choice_three, random_snack_choice_four) # calling the snack
  253. snack_choice = raw_input("What snack would you like? [1-4]")
  254.  
  255. food_choice = int(food_choice) # making the user inputed number into an integer
  256.  
  257. print ('-'*48)
  258.  
  259. if food_choice == 1: # printing the food choice
  260. print "You want %s " % random_food_choice_one
  261. elif food_choice == 2:
  262. print "You want %s " % random_food_choice_two
  263. elif food_choice == 3:
  264. print "You want %s " % random_food_choice_three
  265. elif food_choice == 4:
  266. print "You want %s " % random_food_choice_four
  267. else:
  268. print "No food you you!"
  269. drink_choice = int(drink_choice) # printing the drink choice
  270. if drink_choice == 1:
  271. print "You want %s " % random_drink_choice_one
  272. elif drink_choice == 2:
  273. print "You want %s " % random_drink_choice_two
  274. elif drink_choice == 3:
  275. print "You want %s " % random_drink_choice_three
  276. elif drink_choice == 4:
  277. print "You want %s " % random_drink_choice_four
  278. else:
  279. print "No snack for you!"
  280. snack_choice = int(snack_choice) # printing the snack choice
  281. if snack_choice == 1:
  282. print "You want %s " % random_snack_choice_one
  283. elif snack_choice == 2:
  284. print "You want %s " % random_snack_choice_two
  285. elif snack_choice == 3:
  286. print "You want %s " % random_snack_choice_three
  287. elif snack_choice == 4:
  288. print "You want %s " % random_snack_choice_four
  289. else:
  290. print "No snack for you!"
  291.  
  292. print "Enjoy your meal!"
  293.  
  294. time.sleep(3)
  295. if user_level == 1:
  296. os.system('clear')
  297. admin_commands(user_level)
  298. elif user_level == 0:
  299. os.system('clear')
  300. guest_commands(user_level)
  301.  
  302. def user_level_check(user_level):
  303. print "Please wait..."
  304. time.sleep(3)
  305. if user_level == 1:
  306. os.system('clear')
  307. admin_commands(user_level)
  308. return
  309. elif user_level == 0:
  310. os.system('clear')
  311. guest_commands(user_level)
  312. return
  313.  
  314. user_login(0) # 0 is standard security access level, also starter for program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement