Suppose an amusement park or a different attraction will charge different fares depending on age:
1. Free admission to children under 3 years of age;
Children 2.3 to 12 years old need to buy a child ticket, 10 yuan per sheet;
3. Children and adults over 12 years old are required to buy adult tickets, each 20 yuan;
4. Older people over the age of 60 can buy old age tickets for $15 per piece.
#首先在程序开头可以先编写好相对应提示语句 to let the customer know what to enter:
prompt = "\nPlease enter your age."prompt += "\n(You will know how much you should pay for the ticket):"
#接着就可以用while语句来编辑一个循环的语句. The direct infinite loop statement can be executed with while true:
Input () Inserts the prompt content first and then enters it.
an int (message) is more indispensable in numeric comparisons.
#message里输出的值会是一个字符串. If the user will enter a number and then a comparison between the numbers, you need to convert the message first to the numeric value with the Int () function
The inside of the #用int () function cannot be empty, and the first if statement is infinitely looped when it is empty.
#最后则在while语句中嵌套一个if从句就可以了:
Operation Result:
Use the Python while statement to write a simple ticket and age Calculator