-2

Please help. I am so sorry but I cannot find an answer to make the loop stop after three questions. I've searched for two days. I am brand new at this and trying to teach myself.

Everything runs property until I try to limit the questions to 3.

def get_answer(answer_number):
    if answer_number == 1:
        return "I don't like that question.  I'm not answering you."
    elif answer_number == 2:
        return "Really!?  I'm not answering that."
    elif answer_number == 3:
        return "Ummm, you already know the answer so why are you asking me?"
    elif answer_number == 4:
        return "Focus."
    elif answer_number == 5:
        return "Yawn."

r = random.randint(1, 5)
response = get_answer(r)(tries=3)

while True:
    print("What is your question?")
    question = input()
    if response < 4:
        print(response)
        print()
else:
    print("Would you like to continue with more questions?")
    reply = input().lower()
    if reply == "Y":
        print("Your card will be billed another 1₵.")
    if reply == "N":
        print("Okay.  Amscray!")
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Brenda
  • 1
  • Welcome to Stack Overflow. Please read [ask] and the [formatting help](https://stackoverflow.com/help/formatting), and note well that this is **not a discussion forum**. We are not interested in your personal frustrations; we are interested only in your **question** - ideally, asked explicitly, starting with a question word like "why" or "how", and ending with a question mark (`?`). "Please help" [is not answerable](https://meta.stackoverflow.com/questions/284236/), and "everything works fine until" does not describe a problem nor ask a question. – Karl Knechtel Aug 12 '22 at 02:29
  • As for the code shown: think carefully about the indentation - specifically, how the `else` block should be indented. – Karl Knechtel Aug 12 '22 at 02:30
  • Also: think carefully about what `reply = input().lower()` means. Could the resulting `reply` ever be equal to `"Y"`? How? – Karl Knechtel Aug 12 '22 at 02:35

1 Answers1

0

Beacuse you are using lower() method in your reply input and checking for uppercase "Y" and "N" simply replace the lower() method with the upper() method like this :-

reply = input().upper()
Abhay
  • 51
  • 4