Dog Trick & Treat adventure Python program
Dog Trick & Treat adventure Python program
This Dog Trick & Treat adventure Python program has the following characteristics/capabilities/features;
- 3 dogs, with the names "Princess", "Red" and "Patch" respectively. - Each of the dogs has to complete a Trick that leads to it getting a Treat. - There are 8 Tricks that correspond to 8 Treats: 1.SIT = CHEESE Treat! 2.STAY = PEANUT Treat! 3.PAWSHAKE = POPCORN Treat! 4.CRAWL = BLUEBERRY Treat 5.Jump = STRAWBERRY Treat 6.ROLL = BISCUIT 7.RUN = CHICKEN Treat 8.FRISBEE = BEEF Treat - After selecting a number (e.g 1,2,..., 8) you are instructed to enter the name of the Trick corresponding to that number. - The Trick names are case sensitive, and have to be typed in lower case. - Failure to type Trick name in lowercase ( e.g., 'Sit' and 'SIT' instead of exactly as 'sit' will lead you to a TRAP! - If you get Trapped, you must type "Woof" exactly. This gets you out of the trap but Resets the Tricks progress. - The progress of the selected Tricks at any given time is appended visually in a sorted LIST. - The number of selected Tricks is incremented in a COUNTER appended next to the Tricks LIST. - Any redundant Tricks are intelligently discarded, and not appended in the LIST or incremented in the COUNTER. - After completion of all 8 tricks, any dog earns a "Yummy Strip of Bacon"! - Once you select a dog you cannot switch until the Tricks are Completed. - All the Tricks and Treats are similar regardless of the Dog selected in the beginning.
Attached below is the complete Python code that implements all the above characteristics/capabilities/features;
#!/usr/bin/python3 print( "Welcome to A Dog Treat or Treat Aventure!\nWhich Dog do you want to be?\n1.Princess\n2.Red\n3.Patch\n" ) s1 = "nothing" while True: # Take input from the user / player / dog choice = input( "Please select dog name. (Select 1/2/3): " ) print() # Select one from the three dog names listed if choice in ('1', '2', '3'): if choice == '1': s1 = "Princess!" print("Hello,", s1, ) elif choice == '2': s1 = "Red!" print("Hello,", s1) elif choice == '3': s1 = "Patch!" print("Hello,", s1) break else: print("Woof! Invalid Name!") print() def printIntro(): print( "Which Trick do you want to do to earn a Treat? [Select from the following tricks:](\n1.SIT = CHEESE Treat!\n2.STAY = PEANUT Treat!\n3.PAWSHAKE = POPCORN Treat!\n4.CRAWL = BLUEBERRY Treat\n5.Jump = STRAWBERRY Treat\n6.ROLL = BISCUIT\n7.RUN = CHICKEN Treat\n8.FRISBEE = BEEF Treat" ); printIntro() print() def printMenu(): dogTricks = [1, 2, 3, 4, 5, 6, 7, 8] tricksComplete = [] while len(tricksComplete) != len( dogTricks): # Take input from the user / player / dog choice = input( "Please choose a Dog Trick [Enter a number between 1 to 8]. \n\n(Note that All the commands are Case Sensitive and have to be typed in lower case, e.g., sit exactly as 'sit'! 'Sit' and 'SIT' will lead you to a trap!): " ) # Check if choice is one of the three dog name options if int(choice) in dogTricks: if int(choice) == 1: print(s1, "Please, Sit! [Type the word Sit.]" ) command = input(">>> ") # All the commands are Case Sensitive and have to be typed in lower case, e.g., sit exactly as 'sit'!'Sit' and 'SIT' will lead you to a trap! if command == 'sit': print( "Good Dog! You earned a CHEESE Treat! Now do the next Trick to earn another Treat!" ) if choice in tricksComplete: tricksComplete.remove(choice) tricksComplete.append(choice) tricksComplete.sort() print("\n" + str(tricksComplete) + " --> " + str(len( tricksComplete))) print() else: # Woof in the Kernel Trap is Case sensitive and has to be typed in as exactly 'Woof' while command != 'sit': print( "You just got trapped in a kernel for entering the wrong word!" ) getFree = input( "To break free, type in -Woof-: " ) print() if getFree == 'Woof': printMenu() elif int(choice) == 2: print(s1, "Please, Stay![Type the word Stay.]" ) command = input(">>> ") if command == 'stay': print( "Good Dog! You earned a PEANUT Treat! Now, do the next Trick to earn another Treat!" ) if choice in tricksComplete: tricksComplete.remove(choice) tricksComplete.append(choice) tricksComplete.sort() print("\n" + str(tricksComplete) + " --> " + str(len( tricksComplete))) print() else: while command != 'stay': print( "You just got trapped in a kernel for entering the wrong word!" ) getFree = input( "To break free, type in -Woof-: " ) print() if getFree == 'Woof': printMenu() elif int(choice) == 3: print(s1, "Please, Pawshake!(Type the word Paw.]" ) command = input(">>> ") if command == 'paw': print( "Good Dog! You earned a POPCORN Treat! Now, do the next Trick to earn another Treat!" ) if choice in tricksComplete: tricksComplete.remove(choice) tricksComplete.append(choice) tricksComplete.sort() print("\n" + str(tricksComplete) + " --> " + str(len( tricksComplete))) print() else: while command != 'paw': print( "You just got trapped in a kernel for entering the wrong word!" ) getFree = input( "To break free, type in -Woof-: " ) print() if getFree == 'Woof': printMenu() elif int(choice) == 4: print(s1, "Please, Crawl!(Type the word Crawl.]" ) command = input(">>> ") if command == 'crawl': print( "Good Dog! You earned a BLUEBERRY Treat!Now, do the next Trick to earn another Treat!" ) if choice in tricksComplete: tricksComplete.remove(choice) tricksComplete.append(choice) tricksComplete.sort() print("\n" + str(tricksComplete) + " --> " + str(len( tricksComplete))) print() else: while command != 'crawl': print( "You just got trapped in a kernel for entering the wrong word!" ) getFree = input( "To break free, type in -Woof-: " ) print() if getFree == 'Woof': printMenu() elif int(choice) == 5: print(s1, "Please, Jump! [Type the word Jump.]" ) command = input(">>> ") if command == 'jump': print( "Good Dog! You earned a STRAWBERRY Treat! Now, do the next Trick to earn another Treat!" ) if choice in tricksComplete: tricksComplete.remove(choice) tricksComplete.append(choice) tricksComplete.sort() print("\n" + str(tricksComplete) + " --> " + str(len( tricksComplete))) print() else: while command != 'jump': print( "You just got trapped in a kernel for entering the wrong word!" ) getFree = input( "To break free, type in -Woof-: " ) print() if getFree == 'Woof': printMenu() elif int(choice) == 6: print(s1, "Please, Roll![Type the word Roll.]" ) command = input(">>> ") if command == 'roll': print( "Good Dog! You earned a BISCUIT treat! Now, do the next Trick to earn another Treat!" ) if choice in tricksComplete: tricksComplete.remove(choice) tricksComplete.append(choice) tricksComplete.sort() print("\n" + str(tricksComplete) + " --> " + str(len( tricksComplete))) print() else: while command != 'roll': print( "You just got trapped in a kernel for entering the wrong word!" ) getFree = input( "To break free, type in -Woof-: " ) print() if getFree == 'Woof': printMenu() elif int(choice) == 7: print(s1, "Please, Run![Type the word Run.]" ) command = input(">>> ") if command == 'run': print( "Good Dog! You earned a CHICKEN Treat! Now, do the next Trick to earn another Treat!" ) if choice in tricksComplete: tricksComplete.remove(choice) tricksComplete.append(choice) tricksComplete.sort() print("\n" + str(tricksComplete) + " --> " + str(len( tricksComplete))) print() else: while command != 'run': print( "You just got trapped in a kernel for entering the wrong word!" ) getFree = input( "To break free, type in -Woof-: " ) print() if getFree == 'Woof': printMenu() elif int(choice) == 8: print(s1, "Please catch the Frisbee![Type the word Frisbee.]" ) command = input(">>> ") if command == 'frisbee': print( "Good Dog! You earned a BEEF Treat! Now, do the next Trick to earn another Treat!" ) if choice in tricksComplete: tricksComplete.remove(choice) tricksComplete.append(choice) tricksComplete.sort() print("\n" + str(tricksComplete) + " --> " + str(len( tricksComplete))) print() else: while command != 'frisbee': print( "You just got trapped in a kernel for entering the wrong word!" ) getFree = input( "To break free, type in -Woof-: " ) print() if getFree == 'Woof': printMenu() else: print( "Input a number in the range 1-8 inclusive!" ) print() printMenu() else: congratsDog = "\n\nYou have completed all 8 tricks! You have now earned a Yummy Strip of Bacon\n\n" print("CONGRATS " + s1.upper() + "! " + congratsDog.upper()) printMenu()
To run the above Python code, save in it in a file using your Text editor of choice as “Dog-Treat-Trick-Adventure.py“. To run the code;
python Dog-Treat-Trick-Adventure.py
python3 Dog-Treat-Trick-Adventure.py
Sample results for running the code above are shown in attached screenshots;
Dog Trick & Treat adventure Python program
Python | thetqweb