0

I would like to restart my python code from the beginning after a given "yes" input from the user, but I can't understand what I'm doing wrong here:

if input("Other questions? ") == 'yes' or 'yeah':
    main()
else:
    pass

my code is included within the function main(). Thanks for the help!!

  • 1
    Can you elaborate on what is going wrong? – Loic RW Feb 25 '21 at 08:35
  • To whoever closed this question, the question/answer you linked to appears totally unrelated to this question? – kamion Feb 25 '21 at 08:39
  • @kamion No, `input("Other questions? ") == 'yes' or 'yeah'` is the problem, and the question linked explains how to fix it. (Note: I didn't close the question) – abhigyanj Feb 25 '21 at 08:46

1 Answers1

2

You would probably do it with a while loop around the whole thing you want repeated, and as Loic RW said in the comments, just break out of the while loop:

while True:
    # do whatever you want

    # at the end, you ask your question:
    if input("Other questions? ") in ['yes','yeah']:
        # this will loop around again
        pass
    else:
        # this will break out of the while loop
        break
kamion
  • 461
  • 2
  • 9