0
How do you put error text in a loop?
My program is somewhat like this: while True: print("^^^options^^^") print() print("select your number") print("bin [1]") print("ban [2]") print("bun [3]") user_input = input("==> ") (#the rest is output of 1 , 2, and 3) if i were put a number other than 1, 2 , 3, you guys know that the script will loop to the 1st line. Is there any way to put an error text like" You enter a wrong number. Please check your input" before it back to the 1st line? Thank you. Sorry for asking a noob question!!!
7 Answers
+ 3
raise(#your error): Only works for existing errors in Python
OR
if #condition:
#your error
#your code: You can create your own error
Also we were beginners once too
+ 3
how about after the last line you add
if (user_input > 3):
print("error! wrong number! try again.")
+ 3
lst = ['1', '2', '3']
if (user_input not in lst):
// error
+ 2
Ypu can use raise everywhere
+ 1
@Ali Emir Kizir:
i still confused.
Where should i put this 'raise' thing btw?
Tried once and don't get what it mean :p
Can you please write down a simple script that contain 'raise'?
+ 1
@Mario Laurisch
JUST TRIED IT ON QPYTHON 3 AND IT WORK LIKE MAGIC!!!
THANK YOU VERY MUCH
Now I can continue my project!
Case closed
0
@Mario Laurisch
Hm, i think it was true for integer type input.
However, what if the user somewhat type a string? Thanks BTW, I can see some light :p