The Roast Machine

Step 3 of 3

Keep it running

Keep it running

Two upgrades: wrap the whole thing in a loop so it keeps going, then add protection so one name can never be roasted.


Part A β€” The loop

πŸ” while loop πŸ›‘ break

Wrap your roast code in a while True loop so it keeps asking until the user types quit:

while True: name = input("Enter a name (or 'quit' to stop): ") if name == "quit": break level = input("Pick a roast level β€” mild or savage: ").lower() # ... rest of your roast code here

Things to figure out:

  • What does while True mean β€” why doesn't it stop on its own?
  • What does break do?
  • Where exactly does the roast logic go inside the loop?

Part B β€” Self-roast protection

πŸ”€ if/else πŸ“ String comparison

Before generating the roast, check if the name matches a protected name. If it does, print a special message instead:

your_name = "Ms Johnson" # change this to whatever name you want to protect if name == your_name: print("Nice try. I don't roast legends.") else: roast = random.choice(starters) + " " + name + ", " + random.choice(middles) + " " + random.choice(endings) print(roast)

Put Part A and Part B together in the editor below. The full program should:

  1. Loop forever until the user types quit
  2. Ask for a name and roast level
  3. Skip the roast if the name is protected
  4. Otherwise generate and print the roast
Loading Python runtime…
Try it here
Loading...
bash
$ Click "Run" to execute your code...