Home > other >  Small white to ask: can you tell me I judge the age of the script writing is better?
Small white to ask: can you tell me I judge the age of the script writing is better?

Time:09-27

 
Text="fare we calculate according to the age"
The text +="\ n please enter your age:"
Age=True # to design a loop variable and True
While the age:
Try:
Age=input (text)
Num=float (age) # judge book ever to digital
While the age: # cycle it
If the int (age) & lt;=3:
Print (" free ")
Break
Elif int (age) & lt;=12:
Print (" 12 yuan ")
Break
Elif int (age) & gt;=12:
Print (" 15 yuan ")
Break
The continue # if input is correct, then continue, error code except the following
Except:
If the 'quit' in the age:
Print (' withdrawn ')
Break
The else:
Print (' input is wrong! Please enter the digital age. ')

CodePudding user response:

If you don't consider input negative situation,
This optimization can also,

 

Text="fare we calculate according to the age"
The text +="\ n please enter your age:"
While True:
Age=input (text)
If the 'quit' in the age:
Print (' withdrawn ')
Break
Try:
Num=float (age) # judge book ever to digital
Info="free" if int (age) & lt;=3 else (" 12 yuan "if int (age) & lt; 12 the else="15 yuan")
Print (info)
Except:
Print (' input is wrong! Please enter the digital age. ')

CodePudding user response:

 try: 
Age=input (text)
Num=float (age) # judge book ever to digital
Result="free" if int (age) & lt;=3 else "12 yuan" if int (age) & lt;=12 else "15 yuan
"Print (result)

CodePudding user response:

Thanks to two learning by teaching
  • Related