Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # class notes 4/26/16
- # https://trinket.io/python/c0d1d5470e
- import os
- import time
- import random
- global admin_login_accounts
- global guest_login_accounts
- admin_login_accounts = ['admin']
- guest_login_accounts = ['guest']
- def user_login(user_level):
- transaction_number_generator()
- inputted_name = raw_input("What is your username: \n")
- if inputted_name in admin_login_accounts:
- print "Access granted, welcome back admin. Access Code: %s" % transaction_number
- user_level = user_level+1
- admin_commands(user_level)
- elif inputted_name in guest_login_accounts:
- print "Access granted, welcome to the computer guest. Access Code: %s" % transaction_number
- guest_commands(user_level)
- else:
- print "Access Denied"
- user_login(0)
- return
- def admin_commands(user_level):
- print """
- 1. User Settings
- 2. Games
- 3. Power Down/Log Out
- """
- admin_choice = raw_input("What would you like to run? \n")
- admin_choice=int(admin_choice)
- if admin_choice == 1:
- os.system('clear')
- user_settings(user_level)
- elif admin_choice == 2:
- os.system('clear')
- games(user_level)
- elif admin_choice == 3:
- os.system('clear')
- power_down_logout(user_level)
- else:
- print "Invalid Input"
- time.sleep(3)
- os.system('clear')
- admin_commands(user_level)
- def guest_commands(user_level):
- print """
- 1. Games
- 2. Power Down
- 3. Return to Menu
- """
- guest_choice = raw_input("What would you like to run? \n")
- guest_choice=int(guest_choice)
- if guest_choice == 1:
- os.system('clear')
- games(user_level)
- elif guest_choice == 2:
- os.system('clear')
- power_down_logout(user_level)
- else:
- print "Invalid Input"
- time.sleep(3)
- os.system('clear')
- guest_commands(user_level)
- def user_settings(user_level):
- print """
- 1. Create Admin
- 2. Create Guest
- 3. Return to Menu
- """
- user_settings_choice = raw_input("What would you like to run? \n")
- user_settings_choice = int(user_settings_choice)
- if user_settings_choice == 1:
- os.system('clear')
- create_admin_account(user_level)
- elif user_settings_choice == 2:
- os.system('clear')
- create_guest_account(user_level)
- elif user_settings_choice == 3:
- user_level_check(user_level)
- def games(user_level):
- print """
- 1. Random Number Guesser
- 2. Commons Lunch Generator
- 3. Return to Menu
- """
- games_choice = raw_input("What would you like to run? \n")
- games_choice = int(games_choice)
- if games_choice == 1:
- os.system('clear')
- random_number_game(user_level)
- elif games_choice == 2:
- os.system('clear')
- food_menu(user_level)
- elif games_choice == 3:
- user_level_check(user_level)
- def power_down_logout(user_level):
- print """
- 1. Log Out
- 2. Power Down
- 3. Return to Menu
- """
- power_logout_choice = raw_input("What would you like to run? \n")
- power_logout_choice = int(power_logout_choice)
- if power_logout_choice == 1:
- os.system('clear')
- user_login(0)
- elif power_logout_choice == 2:
- time.sleep(1)
- print "Shut down in \n3..."
- time.sleep(1)
- print "2..."
- time.sleep(1)
- print "1..."
- time.sleep(1)
- os.system('clear')
- return
- elif power_logout_choice == 3:
- user_level_check(user_level)
- def transaction_number_generator():
- global transaction_number # can be acessed in other
- sequence_letter_one = random.choice(['a','b','c','d','e','f','g'])
- sequence_letter_two = random.choice(['a','b','c','d','e','f','g'])
- sequence_letter_three = random.choice(['a','b','c','d','e','f','g'])
- sequence_number_one = random.choice(['1','2','3','4','5','6','7','8','9','0'])
- sequence_number_two = random.choice(['1','2','3','4','5','6','7','8','9','0'])
- transaction_number = "%s%s%s%s%s" % (sequence_letter_one,sequence_letter_two,sequence_number_one,sequence_letter_three,sequence_number_two)
- def create_admin_account(user_level):
- new_admin_name = raw_input("Enter the new login:\n")
- admin_login_accounts.append(new_admin_name)
- "%s is now an admin login."
- os.system('clear')
- admin_commands(user_level)
- def create_guest_account(user_level):
- new_guest_name = raw_input("Enter the new login:\n")
- guest_login_accounts.append(new_guest_name)
- "%s is now a guest login."
- os.system('clear')
- admin_commands(user_level)
- def random_number_game(user_level):
- import random # import random
- global random_number
- random_number = random.choice(range(1, 51)) # Generating random number
- def name_input():
- global user_name # so name can be used in other function
- user_name = raw_input("What is your name? \n")
- print "Okay %s, let's play!\n" % user_name
- def number_check(guess_counter, user_level):
- transaction_number_generator()
- user_guess=raw_input("Pick a number between 1 and 50 \n") # user input for guess
- user_guess=int(user_guess)
- while guess_counter <= 7:
- if 50 >= user_guess > random_number:
- 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
- number_check(guess_counter+1, user_level)
- return
- elif 0 < user_guess < random_number:
- 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
- number_check(guess_counter+1, user_level)
- return
- elif user_guess >= 51: # dodoesnt consume guess for invalid answer
- print "That's not an answer! The number is less than or equal to 50!\nAccess Token: %s\n" % transaction_number
- number_check(guess_counter, user_level)
- return
- elif user_guess <= 0: # "
- print "That's not an answer! The number is greater than or equal to 1!\nAccess Token: %s\n" % transaction_number
- number_check(guess_counter, user_level)
- return
- elif user_guess == random_number:
- print 'You Win %s! You got it in %s guesses! \nAccess Token: %s' % (user_name, guess_counter, transaction_number) # correct
- user_level_check(user_level)
- return
- else: # for the instance of running out of guesses
- if 50 >= user_guess > random_number:
- 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)
- user_level_check(user_level)
- elif 0 < user_guess < random_number:
- 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)
- user_level_check(user_level)
- elif user_guess == random_number:
- print "You Win %s! You got it in %s guesses! \nAccess Token: %s" % (user_name, guess_counter, transaction_number) # correct
- user_level_check(user_level)
- elif user_guess >= 51: # dodoesnt consume guess for invalid answer
- print "That's not an answer! The number is less than or equal to 50!\nAccess Token: %s\n" % transaction_number
- number_check(guess_counter, user_level)
- return
- elif user_guess <= 0: # "
- print "That's not an answer! The number is greater than or equal to 1!\nAccess Token: %s\n" % transaction_number
- number_check(guess_counter, user_level)
- return
- name_input() # Calling function for user to input name
- number_check(1, user_level) # using 0 to have 8 guesses, to have less change number to be 8-inputted number = guesses
- def food_menu(user_level):
- print (48*'-')
- print "What would you like to eat in the commons today?"
- print (48*'-')
- print "\t\t F O O D - M E N U"
- print (48*'-')
- import random # importing the module
- def food(random_food_one, random_food_two, random_food_three, random_food_four): # function for displaying the food
- print "1. %s" % random_food_one
- print "2. %s" % random_food_two
- print "3. %s" % random_food_three
- print "4. %s" % random_food_four
- def drink(random_drink_one, random_drink_two, random_drink_three, random_drink_four): # function for displaying the drink
- print "1. %s" % random_drink_one
- print "2. %s" % random_drink_two
- print "3. %s" % random_drink_three
- print "4. %s" % random_drink_four
- def snack(random_snack_one, random_snack_two, random_snack_three, random_snack_four): # function for displaying the snack
- print "1. %s" % random_snack_one
- print "2. %s" % random_snack_two
- print "3. %s" % random_snack_three
- print "4. %s" % random_snack_four
- # making the randomizer for foods
- random_food_choice_one = random.choice(["BLT","Bacon-egg and cheese","Grilled-Cheese","Hot-dog","Burger","French-Fries","Rice","Bagel","Grilled-Fish"])
- random_food_choice_two = random.choice(["BLT","Bacon-egg and cheese","Grilled-Cheese","Hot-dog","Burger","French-Fries","Rice","Bagel","Grilled-Fish"])
- random_food_choice_three = random.choice(["BLT","Bacon-egg and cheese","Grilled-Cheese","Hot-dog","Burger","French-Fries","Rice","Bagel","Grilled-Fish"])
- random_food_choice_four = random.choice(["BLT","Bacon-egg and cheese","Grilled-Cheese","Hot-dog","Burger","French-Fries","Rice","Bagel","Grilled-Fish"])
- # making the randomizer for drinks
- random_drink_choice_one = random.choice(["Pepsi","Sprite","Coke","Aloe drink","Sunkist","Ginger-Ale","Lemonade","Naked-Smoothie"])
- random_drink_choice_two = random.choice(["Pepsi","Sprite","Coke","Aloe drink","Sunkist","Ginger-Ale","Lemonade","Naked-Smoothie"])
- random_drink_choice_three = random.choice(["Pepsi","Sprite","Coke","Aloe drink","Sunkist","Ginger-Ale","Lemonade","Naked-Smoothie"])
- random_drink_choice_four = random.choice(["Pepsi","Sprite","Coke","Aloe drink","Sunkist","Ginger-Ale","Lemonade","Naked-Smoothie"])
- # making the randomizer for snacks
- random_snack_choice_one = random.choice(["Chips", "Nerds", "Churro","Cookie","Kit-Kat","Muffin","Snickers","Chocolate","Brownie"])
- random_snack_choice_two = random.choice(["Chips", "Nerds", "Churro","Cookie","Kit-Kat","Muffin","Snickers","Chocolate","Brownie"])
- random_snack_choice_three = random.choice(["Chips", "Nerds", "Churro","Cookie","Kit-Kat","Muffin","Snickers","Chocolate","Brownie"])
- random_snack_choice_four = random.choice(["Chips", "Nerds", "Churro","Cookie","Kit-Kat","Muffin","Snickers","Chocolate","Brownie"])
- food(random_food_choice_one, random_food_choice_two, random_food_choice_three, random_food_choice_four) # calling the food
- 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
- drink(random_drink_choice_one, random_drink_choice_two, random_drink_choice_three, random_drink_choice_four) # calling the drink
- drink_choice = raw_input("What drink would you like? [1-4]")
- snack(random_snack_choice_one, random_snack_choice_two, random_snack_choice_three, random_snack_choice_four) # calling the snack
- snack_choice = raw_input("What snack would you like? [1-4]")
- food_choice = int(food_choice) # making the user inputed number into an integer
- print ('-'*48)
- if food_choice == 1: # printing the food choice
- print "You want %s " % random_food_choice_one
- elif food_choice == 2:
- print "You want %s " % random_food_choice_two
- elif food_choice == 3:
- print "You want %s " % random_food_choice_three
- elif food_choice == 4:
- print "You want %s " % random_food_choice_four
- else:
- print "No food you you!"
- drink_choice = int(drink_choice) # printing the drink choice
- if drink_choice == 1:
- print "You want %s " % random_drink_choice_one
- elif drink_choice == 2:
- print "You want %s " % random_drink_choice_two
- elif drink_choice == 3:
- print "You want %s " % random_drink_choice_three
- elif drink_choice == 4:
- print "You want %s " % random_drink_choice_four
- else:
- print "No snack for you!"
- snack_choice = int(snack_choice) # printing the snack choice
- if snack_choice == 1:
- print "You want %s " % random_snack_choice_one
- elif snack_choice == 2:
- print "You want %s " % random_snack_choice_two
- elif snack_choice == 3:
- print "You want %s " % random_snack_choice_three
- elif snack_choice == 4:
- print "You want %s " % random_snack_choice_four
- else:
- print "No snack for you!"
- print "Enjoy your meal!"
- time.sleep(3)
- if user_level == 1:
- os.system('clear')
- admin_commands(user_level)
- elif user_level == 0:
- os.system('clear')
- guest_commands(user_level)
- def user_level_check(user_level):
- print "Please wait..."
- time.sleep(3)
- if user_level == 1:
- os.system('clear')
- admin_commands(user_level)
- return
- elif user_level == 0:
- os.system('clear')
- guest_commands(user_level)
- return
- user_login(0) # 0 is standard security access level, also starter for program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement