0

in python it seems like try ,except and finally don't use break and continue operation am confus I try including but think erro

need help on this because am working on something

16th Apr 2017, 9:08 PM
Ugwuanyi Arinze Emmanuel
Ugwuanyi Arinze Emmanuel - avatar
5 Answers
+ 3
Well I'm not completely finished with my Python course yet but I do know how to make a code continue until the user inputs a correct string. Example (Python): i = 1 while i > 0: try: name = input("Input name: ") i -= 0 except: print("You entered an invalid name.") -This might not be 100% accurate, but it should give you the general idea here. -The "i" variable controls the loop that the "try/except" code is in. -This loop will only be broken if the user inputs a name that doesn't cause an error. -If the name causes an error then it will skip the part that makes the "i" variable 0 which would've broken the loop. -The user will be asked to input a correct name, that doesn't cause an error, until that "i" variable gets set to 0
16th Apr 2017, 10:02 PM
Ghauth Christians
Ghauth Christians - avatar
+ 2
break and continue can only be used in loops, that's why you're getting errors.
16th Apr 2017, 9:23 PM
Ghauth Christians
Ghauth Christians - avatar
+ 1
What are you trying to do really?
16th Apr 2017, 9:24 PM
Ghauth Christians
Ghauth Christians - avatar
+ 1
@gavin thanks
16th Apr 2017, 9:42 PM
Ugwuanyi Arinze Emmanuel
Ugwuanyi Arinze Emmanuel - avatar
0
@gavin am try to use my on my c drive but it Disappear jus after running and am also try to make my code to continue after someone have entered the wrong input using try and except
16th Apr 2017, 9:46 PM
Ugwuanyi Arinze Emmanuel
Ugwuanyi Arinze Emmanuel - avatar