Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import pickle
- #set up blank list
- xmas = []
- #menu
- while True:
- print("""What would you like to do with the xmas list...
- 1. Add presents and print list
- 2. Sort the list into alphabetical order and print list
- 3. Pick a random present and print it out
- 4. Find out if your list has an i-pad
- 5. Print out how many presents are on the list
- 6. Quit""")
- #get menu item
- choice= input("Please enter your choice ")
- #output dependent on choices
- if choice=="1":
- print ("Choice 1")
- present= input("What is your present? ")
- xmas.append(present)
- out_file = open("christmas.dat","wb")
- pickle.dump(xmas,out_file)
- out_file.close()
- #Program asking you what is your present, you need to put that present you like
- elif choice=="2":
- print ("Choice 2" )
- xmas.sort()
- print(xmas)
- #Program sorting evry presents from A to Z
- elif choice=="3":
- print("Choice 3")
- print(random.choice(present))
- #Program pick random prsesent form your list
- elif choice=="4":
- print("Choice 4")
- if "iPad" in xmas:
- print ("Yep")
- else:
- print("Nah")
- #If you choice nuber 4, you asking program about do you have iPad in your present list if not he write nah if yes he write yep
- elif choice=="5":
- print("Choice 5")
- print("You have",len(xmas), "presents")
- #When you choice number 5 program will preint how many present do you have from your list
- elif choice=="6":
- print("Choice 6")
- break
- #When you choice number 6 your program will finish working and close
- else:
- print ("Invalid choice")
- #when you choice for example 15 program will preint invalid choice
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement