How to restart my program I want it so if the user makes a wrong choice it goes back to the first question. (PYTHON 3) pls help | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

How to restart my program I want it so if the user makes a wrong choice it goes back to the first question. (PYTHON 3) pls help

If more details needed ask in comments section.

3rd Sep 2020, 2:13 AM
C Pitt
C Pitt - avatar
9 Respuestas
+ 2
while True: answer = input("test:") if answer == "hello": print("hello people") break
3rd Sep 2020, 3:01 AM
Nikolai Ivanov
Nikolai Ivanov - avatar
0
Something like this? if (wrong): main()
3rd Sep 2020, 2:20 AM
Steven M
Steven M - avatar
0
Yes but I don't know how to define wrong I'm new
3rd Sep 2020, 2:25 AM
C Pitt
C Pitt - avatar
0
I put wrong into the program and it said "name error wrong not defined" it is a name error.
3rd Sep 2020, 2:28 AM
C Pitt
C Pitt - avatar
0
Yeah it's pseudo code, (wrong) is the result from a condition, like: if input() != answer: main() I think we can help if you share your code
3rd Sep 2020, 2:32 AM
Steven M
Steven M - avatar
0
Ok let me pull it up real quick it is not that long.
3rd Sep 2020, 2:33 AM
C Pitt
C Pitt - avatar
0
print ("hello world") answer = input ("test ") if answer == ("hello"): answer = input (" hello people ")
3rd Sep 2020, 2:39 AM
C Pitt
C Pitt - avatar
0
When I put hello it says hello people but if I type a random word it stops the program but I wanted it to restart if I make a mistake.
3rd Sep 2020, 2:41 AM
C Pitt
C Pitt - avatar
0
Brilliant thank you Nikolai Ivanov
3rd Sep 2020, 1:03 PM
C Pitt
C Pitt - avatar