Home > other >  Python is a small problem
Python is a small problem

Time:09-22


How to ensure that the input for the digital (real)

CodePudding user response:


This program whether Numbers or other characters will prompt error

CodePudding user response:

n.. Isdigit ()

CodePudding user response:

 
Def pm2dot5 () :
While True:
N=input (" please enter a value: PM2.5)
If n=='q:
Break
Try:
Num=int (n)
If num & lt; 35:
Print (" air quality, it is recommended that the outdoor sports, ")
Elif 35 & lt; Num=& lt;=75:
Print (" air quality is good, it is recommended that the moderate outdoor sports, ")
The else:
Print (" air pollution, please be careful!" )
Except:
Print (' data input is not correct, please input again! ')

If __name__=="__main__ ':
Pm2dot5 ()

CodePudding user response:

 n=input (" please enter a value: PM2.5) 
While not n.i sdigit () :
N=input (" please enter a value: PM2.5)
Num=int (n)
Tishi=(lambda num: "air quality, it is recommended that the outdoor sports," if num & lt; 35
The else "air quality is good, it is recommended that the moderate outdoor sports," if 35 & lt; Num=& lt;=75
The else "air pollution, please be careful!" )
Print (tishi (num))

CodePudding user response:

The
reference 4 floor weixin_45903952 reply:
 n=input (" please enter a value: PM2.5) 
While not n.i sdigit () :
N=input (" please enter a value: PM2.5)
Num=int (n)
Tishi=(lambda num: "air quality, it is recommended that the outdoor sports," if num & lt; 35
The else "air quality is good, it is recommended that the moderate outdoor sports," if 35 & lt; Num=& lt;=75
The else "air pollution, please be careful!" )
Print (tishi (num))

Didn't contain real!

CodePudding user response:

reference 5 floor overcomemyself reply:
Quote: refer to 4th floor weixin_45903952 response:
 n=input (" please enter a value: PM2.5) 
While not n.i sdigit () :
N=input (" please enter a value: PM2.5)
Num=int (n)
Tishi=(lambda num: "air quality, it is recommended that the outdoor sports," if num & lt; 35
The else "air quality is good, it is recommended that the moderate outdoor sports," if 35 & lt; Num=& lt;=75
The else "air pollution, please be careful!" )
Print (tishi (num))

Didn't contain real!


Enter a non real number you tried?

CodePudding user response:

 n=input (" please enter a value: PM2.5) 
While not n.i sdigit () :
N=input (" please enter the number:)
Num=int (n)
Tishi=(lambda num: "air quality, it is recommended that the outdoor sports," if num & lt; 35
The else "air quality is good, it is recommended that the moderate outdoor sports," if 35 & lt; Num=& lt;=75
The else "air pollution, please be careful!" )
Print (tishi (num))
  • Related