7-1. Rental Car: Write a program that asks the user what kind of rental car they would like. Print a message about that car, such as “Let me see if I can find you a Subaru.”
知识点分析:Python输入函数input的简单应用
代码:
#7-1
brand = input('What kind of car do you like to rent?\n')
print("Let me see if I can find you a "+brand)
7-3. Multiples of Ten: Ask the user for a number, and then report whether the number is a multiple of 10 or not.
知识点分析:输入练习、%运算符
代码:
#7-3
num = input('please enter an integer\n')
divisible = True if int(num) % 10 == 0 else False
if divisible:
print(num+" is a multiple of 10")
else:
print(num+" is NOT a multiple of 10")
7-5. Movie Tickets: A movie theater charges different ticket prices depending on a person’s age. If a person is under the age of 3, the ticket is free; if they are between 3 and 12, the ticket is $10; and if they are over age 12, the ticket is $15. Write a loop in which you ask users their age, and then tell them the cost of their movie ticket.
7-6. Three Exits: Write different versions of either Exercise 7-4 or Exercise 7-5 that do each of the following at least once:
• Use a conditional test in the while statement to stop the loop.
• Use an active variable to control how long the loop runs.
• Use a break statement to exit the loop when the user enters a 'quit' value.
知识点分析:用户输入交互与while循环
代码:
#7-5&7-6
#solution 1
age = input("Please enter your age('quit' to exit)\n")
while age != 'quit':
if int(age) < 3:
print("free")
elif 3 <= int(age