-4
i = 1
while i != 3:
  if i == 1:
    def main3():
      decision3 = str(input("Do you accept? (Yes or No)"))
      if decision3 == 'No':
          print("narration")
      elif decision3 == 'Yes':
          print("narration")
          i = 2
      else:
          print("Sorry, that is an invalid input. Please re-enter.")
          main3()
    main3()
  else:
      i = 3
      print("narration")

It's supposed to run the code, and if the inout for decision three isn't Yes or No, the user is supposed to re-enter the input. Whenever I run the code, it infinitely asks decision3.

Alec
  • 8,529
  • 8
  • 37
  • 63

1 Answers1

3

The value of i never changes, so main3() is perpetually called.

if i == 1:
    def main3():
      decision3 = str(input("Do you accept? (Yes or No)"))
      if decision3 == 'No':
          print("narration")
      elif decision3 == 'Yes':
          print("narration")
          i = 2  # <-- This does nothing to i outside of main3()!
      else:
          print("Sorry, that is an invalid input. Please re-enter.")
          main3()
    main3()  # <-- This is the problem!

i is only changed within the scope of main3(), not globally.

As a side note, don't cast the return of input() as a string. It already is one.

Alec
  • 8,529
  • 8
  • 37
  • 63