Python 第七章部分练习

7.1 汽车租赁

Python 第七章部分练习

代码:

car = input("Hello ,please tell which car you want to lease\n  car name:")

print("Let me see if I can find you a " + car)


输出(输入为Subarn):

Python 第七章部分练习


7-2 餐馆订位

Python 第七章部分练习

代码:

num = input("Hello ,please tell me how many people have a meal\n number:")
num = int(num)
if num > 8:
    print("Sorry there is no spare table")
else:

    print("Welcome, we have spare tabels")


输出(输入分别为9和7):

Python 第七章部分练习


7-3.10的整数倍

Python 第七章部分练习

代码:

num = input("Hello ,please enter a num and i will tell you" 
            "whether it is an integer multiple of 10\n num :")
num = int(num)
if num % 10 == 0:
    print("It is an integer multiple of 10")
else:

    print("It is not an integer multiple of 10")


输出(输入分别为100和99)

Python 第七章部分练习



7-5 电影票

Python 第七章部分练习

代码:

num = 1
while num >= 0:
    num = input("How old are you?\n"
                "Enter you age(enter a negative num to quit):")
    num = int(num)
    if num >= 0 and num < 3:
        print("The ticket is free\n")
    elif num >= 3 and num <=12:
        print("The ticket price is 10$\n")
    elif num > 12:

        print("The ticket price is 15$\n")


输出(输入分别为6, 3, 2, 15, -1):

Python 第七章部分练习