File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 11# number_input_examples.py
22
3- # This file accompanies the Real Python article "How To Read User Input As Integers".
4- # It contains examples of functions that filter user input for valid integers and floats.
3+ # This file accompanies the Real Python article
4+ # "How To Read User Input As Integers". It contains
5+ # examples of functions that filter user input for
6+ # valid integers and floats.
57
68
79def get_integer (prompt : str , error_message : str = None ) -> int :
@@ -50,12 +52,16 @@ def get_integer_with_default(
5052
5153if __name__ == "__main__" :
5254 print (get_integer ("Testing get_integer(): " ))
53- print (
54- get_integer ("Testing get_integer() with an error message: " , "Invalid integer!" )
55+ print (get_integer (
56+ "Testing get_integer() with an error message: " ,
57+ "Invalid integer!" )
5558 )
56- print (get_float ("Testing get_float() with an error message: " , "Invalid float!" ))
59+ print (get_float
60+ ("Testing get_float() with an error message: " ,
61+ "Invalid float!" ))
5762 print (
5863 get_integer_with_default (
59- "Testing get_integer_with_default(): " , 99 , "That's not a valid integer!"
64+ "Testing get_integer_with_default(): " ,
65+ 99 , "That's not a valid integer!"
6066 )
6167 )
You can’t perform that action at this time.
0 commit comments