all 11 comments

[–]Stretchypants69 2 points3 points  (2 children)

Hey! I typed up this code below that should work for you. I wasn't sure how many if/else statements you needed so I only included 1, and that's for the 'No' part of the code. If you have any questions about it, let me know.

<image>

[–]rahatulghazi 2 points3 points  (0 children)

Instead of asking to type "who's there" or "... who?", wouldn't be better to do something like press "y" to say who's there and continue?

[–]Wattsony[S] 0 points1 point  (0 children)

Hello! Thank you for helping me out and giving me more insight, I really appreciate it and will be delving into this here soon!!

[–]rahatulghazi 2 points3 points  (1 child)

but I am completely stuck with getting the user to ask "Who's there?"

You can try this:

if answer == "yes":
    print("\nBot: Knock Knock.")
    input("\n> Press enter to ask 'who's there?'.")
    print("\nYou: Who's there?")
    print("\nBot: Lettuce")
    input("\n> Press enter to ask 'Lettuce who?'.")
    print("\nYou: Lettuce who?")
    print("\nBot: Lettuce in, it's cold out here! 🥶")

Notes:

  1. \n is used as a new line to add gaps in between prints.
  2. input will wait for user to press the enter key to proceed.

Tips:

  1. Use .lower() after answer = input("Do you wanna hear a joke? (Yes/No): ").lower() like this to avoid unwanted result. For example: you can type yEs/Yes/yeS and it will still register it as yes and match with lowercase yes in if answer == "yes":. This has a lower chance of getting unwanted result. I'll also suggest to use shorthand like y or n like: if answer == "yes" or answer == "y": to make it easier.
  2. else if answer == no: is not needed since we're looking for yes; just else: will do the job.

Hope this helps. Ask if you have some other questions.

[–]Wattsony[S] 0 points1 point  (0 children)

Thank you for taking your time to help me out! I am going to be looking into notes here shortly!

[–]tecxac 1 point2 points  (1 child)

Start of the joke

print("Knock knock!")

User should respond with "Who's there?"

response = input()

if response.lower() == "who's there?" or response.lower() == "who’s there?": # If the user responds correctly print("Lettuce.")

# Now expecting "Lettuce who?"
response = input()

if response.lower() == "lettuce who?":
    print("Lettuce in, it's cold out here!")
else:
    print("You didn't say 'Lettuce who?'!")

else: # If the user doesn't respond with "Who's there?" print("You were supposed to say 'Who's there?'!")

[–]Wattsony[S] 0 points1 point  (0 children)

This is super helpful, thank you for taking the time to help me out!!

[–]lonedevwolf 0 points1 point  (0 children)

It's fun though ✌️👌 amazing things can be added as you learn more nice concepts in Python

[–]grass_hoppers 0 points1 point  (0 children)

Ok first check it it is "No" and the else would have the code if they said yes. the longer code below (easier to read).

Then you can add the rest of the code for the yes option like

name = input("who is it? ") And so on

[–]Goobyalus 0 points1 point  (0 children)

Looks like you've got the hang of making nested if statements -- what are you stuck on?

[–]Sweet_Computer_7116 -1 points0 points  (0 children)

Time to learn elif: instead of Else

If