+ 2

How to prevent error when user use spacebar before typing in user input?? Need some help #python

Have you tried typing space bar before input you data in python what did you get, and how can one stop such error message. Thanks

17th Feb 2022, 1:22 PM
WISDOM M URANGYORK
WISDOM M URANGYORK - avatar
3 odpowiedzi
+ 3
Please link your code and describe the expected input
17th Feb 2022, 1:29 PM
Lisa
Lisa - avatar
+ 3
You may want to trim the input before use it in your code. Have a look at strip(), lstrip(), rstrip() functions.
17th Feb 2022, 1:34 PM
Geoffrey L
Geoffrey L - avatar
+ 2
Why should there be an error? I tried these and got valid results i1 = int( input() ) # input " 2022" f1 = float( input() ) # input " 2022.1702" print( i1, f1 ) String input works fine as well ... You may also wrap the input reading block inside a try...except block in anticipation of data conversion error.
17th Feb 2022, 1:29 PM
Ipang