Input Validation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Input Validation

I’m trying to write a block of code that will only accept floats, integers, and the letter ‘d’. For some reason, the structure I have isn’t working. Am I going about this the wrong way? Any help would be greatly appreciated. https://code.sololearn.com/c4SHeEEFvLpG/?ref=app

24th Apr 2018, 5:20 AM
Michael Godfrey
Michael Godfrey - avatar
2 Answers
+ 3
Hi, try it changing it to this: while True: m = input('Please enter a measurement: ') try: data.append(float(m)) It seems to work.
24th Apr 2018, 6:26 AM
Paul
Paul - avatar
+ 1
It works! Thank you!
24th Apr 2018, 7:29 AM
Michael Godfrey
Michael Godfrey - avatar