Use the Python while statement to write a simple ticket and age Calculator

Source: Internet
Author: User
Tags ticket
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.