Advertisement
BabbaYagga

Questionnaire

May 2nd, 2024 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | Source Code | 0 0
  1. """ myemoji.py """
  2. emojis = dict(
  3.     sadface="\U0001F61E",
  4.     grinningface="\U0001F600",
  5.     wavinghand="\U0001F44B",
  6.     thumbsup="\U0001F44D",
  7.     thumbsdown="\U0001F44E",
  8.     handshake="\U0001F91D",
  9. )
  10.  
  11. """ main.py """
  12. import os
  13. from myemoji import emojis
  14.  
  15. def yesno(question):
  16.  
  17.     while True:
  18.         prompt = f"{question} [y/n]: "
  19.         ans = input(prompt).strip().lower()[:1]
  20.  
  21.         if ans not in ["y", "n"]:
  22.             continue
  23.         if ans == "y":
  24.             return True
  25.  
  26.         return False
  27.  
  28.  
  29. def main():
  30.     os.system('cls' if os.name == 'nt' else 'clear')
  31.     myName = input("\n\n\tWhat is your name? ")
  32.  
  33.     if len(myName) > 0:
  34.         myName = myName.title()
  35.         print(f"\tHello, {myName}. I'm Python, glad to meet you! {emojis['handshake']}")
  36.  
  37.         if yesno("\tDo you have a pet?"):
  38.             print(f"\tThat's great! {emojis['thumbsup']} ", end=" ")
  39.             petName = input("What's your pet's name? ")
  40.  
  41.             if len(petName) > 0:
  42.                 petName = petName.title()
  43.                 petAge = input(f"\tHow old is \"{petName}\"? ")
  44.                 units = "year"
  45.  
  46.                 if int(petAge) > 1:
  47.                     units += "s"
  48.  
  49.                 print(f"\t{myName} has a pet named \"{petName}\". {petName} is {petAge} {units} old.\n\n")
  50.         else:
  51.             print(f"\t{myName.title()} doesn't have a pet... how sad! {emojis['sadface']}\n\n")
  52.  
  53. if __name__ == "__main__":
  54.     main()
  55.  
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement