《python编程从入门到实践》第7章 用户输入和while循环(练习)

如题:

7-1汽车租赁:编写一个程序,询问用户要租赁什么样的汽车,并打印一条消息,如“Let me see if I can find you  a Subaru.”

7-2餐馆定位:编写一个程序,询问用户有多少人用餐。如果超过8人,就打印一条消息,指出没有空桌;否则指出有空桌。

7-3 10的整数倍:让用户输入一个数字,并指出这个数字是否是10的整数倍。

7-4 比萨配料:编写一个循环,提示用户输入一系列的比萨配料,并在用户输入'quit'时结束循环。每当用户输入一种配料后,都打印一条消息,说我们会在pizza中添加这种配料。

7-5电影票:有家电影院根据观众的年龄收取不同的票价:不到3岁的观众免费;3~12岁的观众为10美元;超过12岁的观众15美元。请编写一个循环,在其中询问用户的年龄,并指出其票价。

7-7无限循环

7-8熟食店:创建一个名为sandwich_orders的列表,在其中包含各种三明治的名字;再创建一个名为finished_sandwiches的空列表。遍历列表sandwich_orders,对于其中的每种三明治,都打印一条消息,如I made your tuna sandwich, 并将其移到列表finished_sandwiches。所有三明治制作好后,打印一条消息,将这些三明治列出来。

7-9五香烟熏牛肉卖完了:再7-8列表中五香烟熏牛肉至少出现三次,打印一条消息指出熟食店的五香烟熏牛肉买完了,再使用while循环将列表sandwich_orders中的五香烟熏牛肉的删除,最终确认列表不包含五香烟熏牛肉。

7-10梦想的度假胜地:编写一个程序,调查用户梦想度假胜地,并打印调查结果。

#7-1
car = input('What kind of car would you like?')
print('Let me see if I can find you a '+car)


#7-2
number = input('How many people have dinner?')
number =  int(number)
if number>8:
    print('no table!')
else:
    print('okk')


#7-3
user = input('Please input a number:')
user = int(user)

if user % 10 == 0:
    print('This number is an integer multiple of 10.')
else:
    print('This number is not an integer multiple of 10.')


#7-4
word1 = 'Please choose an ingradient:'
word2 = 'We will add this ingredient soon!'
message = ''
while message != 'quit':
    message = input(word1)
    if message !='quit':
        print(word2)


#7-5

message = ''
while message!='quit' :
    word = input('How old are you?')
    word1 = int(word)
    if word1 < 3:
        print('You are free!')
        continue
    elif 3<= word1 <=12:
        print('10 dollars!')
        continue
    elif 12< word1:
        print('15 dollars!')
        continue


#7-7 无限循环
numb = 1
numb = int(numb)
while numb < 5:
    print('ooo')


# 7-8
sandwich_orders = ['水果三明治','培根三明治','金枪鱼三明治']
finished_sandwiches = []
while sandwich_orders:
    finished_sandwich = sandwich_orders.pop()
    print('我给你做了'+finished_sandwich+'。')
    finished_sandwiches.append(finished_sandwich)

print('您点了这些三明治:')
for finished_sandwich in finished_sandwiches:
    print(finished_sandwich)



#7-9
print('')
sandwich_orders = ['水果三明治','培根三明治','五香烟熏牛肉','金枪鱼三明治','五香烟熏牛肉','五香烟熏牛肉']
print('五香烟熏牛肉卖完了')

while '五香烟熏牛肉' in sandwich_orders:
    sandwich_orders.remove('五香烟熏牛肉')
    
print(sandwich_orders)


#7-10
print('')
responses = {}

polling_active = True
while polling_active:
    name = input('What is your name?')
    ques = input('If you could visit one place in the world,where would you go?')
    responses[name] = ques
    polling_active = False

print('Poll results:')
for name,ques in responses.items():
    print(name.title()+" want to visit "+ques+'.')

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值