Error handling with random number [solved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Error handling with random number [solved]

Hi all! I did the following paractise code. https://code.sololearn.com/cyqK6NM27Q1Y/#py My problem is: if you do not press 'c', 'l' or 'h', the program repeats the question but with a different random number. I would like the program to keep the original random number until the users enters a valid input (which is 'c', 'l' or 'h'). Thanks in advance for your help!

30th Jun 2020, 7:39 AM
Matthias Seidl
3 Answers
+ 2
Just put the a=rd(low,up) in front of the while sloop....then it will not be changed each time If you then want it to be changed if h was touched you can add this statement there in the if case...
30th Jun 2020, 7:50 AM
Alexander Thiem
Alexander Thiem - avatar
+ 1
Thanks Alexander. Works perfectl now.
30th Jun 2020, 8:00 AM
Matthias Seidl
0
Cool👍
30th Jun 2020, 11:04 AM
Alexander Thiem
Alexander Thiem - avatar