Home > other >  Python consult a great god for decimal problem
Python consult a great god for decimal problem

Time:01-21

Great god, please give directions, thank you very much: I am a self-taught small white, can enter the following code integer, such as 123456, if the input decimals, such as 123456.789 the first step is directly determine false, output "you input incorrect" as a result, how to modify to get an integer or decimal are involved in the program?
Money=input (' please enter your monthly salary: '). The strip ()
If money. Isdecimal () :
Money=float (money)
If money & gt; 10000:
Print (' champagne ')
The else:
Print (' wash your sleep)
The else:
Print (' your input is not correct)

CodePudding user response:

Should be isdecimal () does not include the decimal point, so the first step is judged to be False,
Directly with the try to keep it simple: float (money), if error will re-enter,
Or just use regular expressions to determine whether money meets the requirements,
  • Related