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))