Facebook
From Sgsag, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 156
  1. def purchase_flag(balance):
  2.     while True:
  3.         print("Welcome to the CTF Store Challenge!")
  4.         print("Your balance: $" + str(balance))
  5.         print("Options:")
  6.         print("1. Curtains of Houses - $4")
  7.         print("2. Dining Table - $30")
  8.         print("3. Flag of the Office - $49")
  9.         print("4. Another item (Search for items)")
  10.         print("5. Exit")
  11.  
  12.         choice = input("Enter your choice: ")
  13.  
  14.         if choice == "1":
  15.             if balance >= 4:
  16.                 balance -= 4
  17.                 print("You purchased the Curtains of Houses. Your balance is now $" + str(balance))
  18.             else:
  19.                 print("You don't have enough money to buy the Curtains of Houses.")
  20.  
  21.         elif choice == "2":
  22.             if balance >= 30:
  23.                 balance -= 30
  24.                 print("You purchased the Dining Table. Your balance is now $" + str(balance))
  25.             else:
  26.                 print("You don't have enough money to buy the Dining Table.")
  27.  
  28.         elif choice == "3":
  29.             if balance >= 49:
  30.                 balance -= 49
  31.                 print("Congratulations! You purchased the Flag of the Office, which is the challenge flag.")
  32.                 print("Your balance is now $" + str(balance))
  33.                 return True
  34.             else:
  35.                 print("You don't have enough money to buy the Flag of the Office.")
  36.  
  37.         elif choice == "4":
  38.             while True:
  39.                 print("Searching for item...")
  40.                 item = input("Enter the item you want to search for: ")
  41.                 try:
  42.                     result = eval(item)
  43.                     balance = result
  44.                     print("Sorry, the item you are looking for is not available.")
  45.                 except Exception:
  46.                     print("Invalid input. Please enter a valid expression.")
  47.                 print("Options:")
  48.                 print("1. Search again")
  49.                 print("2. Back to list")
  50.  
  51.                 search_choice = input("Enter your choice: ")
  52.                 if search_choice == "1":
  53.                     continue
  54.                 elif search_choice == "2":
  55.                     break
  56.                 else:
  57.                     print("Invalid choice. Returning to the list of options.")
  58.  
  59.         elif choice == "5":
  60.             print("Exiting the CTF Store Challenge. Goodbye!")
  61.             return False
  62.  
  63.         else:
  64.             print("Invalid choice. Please enter a number between 1 and 5.")
  65.  
  66. balance = 10
  67. purchase_flag(balance)
  68.