习题 7-1
汽车租赁 :编写一个程序,询问用户要租赁什么样的汽车,并打印一条消息,如“Let me see if Ican find you a Subaru”。
print('What car would you like to rent?')
#输入汽车类型
car_type = input()
print("Let me see if Ican find you a " + car_type)
运行结果:
习题 7-2
餐馆订位 :编写一个程序,询问用户有多少人用餐。如果超过8人,就打印一条消息,指出没有空桌;否则指出有空桌。
print('这里是太后大酒楼,请问几位用餐:')
num = int(input())
if num > 8:
print('不好意思,没有空桌了。')
else:
print('欢迎光临!')
运行结果:
习题 7-3
10的整数倍 :让用户输入一个数字,并指出这个数字是否是10的整数倍。
print('Please input a number')
num = int(input())
#判断是否是整数倍
if num % 10 == 0:
print('Yes')
else:
print('No')
运行结果: