python编程:从入门到实践-第七章练习

#7-1
print ( 'what kind of car do you want?' )
car = input ()
print ( 'let me see if i can find you a %s ' % car)

#7-2
number = input ( 'how many people ?' )
if int (number) > 8 :
print ( 'we are out of table!' )
else :
print ( 'ok!' )
#7-3
number = int ( input ( 'give me a number!' ))
if number % 10 == 0 :
print ( 'True' )
else :
print ( 'False' )

#7-4
print ( '给我们些披萨配料!' )
s = input ()
while s != 'quit' :
print ( 'we will add %s to it' % s)
s = input ()
#7-5

age = int ( input ( 'your age?' ))
while True :
if age >= 3 and age <= 12 :
print ( '10 dollar' )
elif age < 3 :
print ( 'free' )
else :
print ( '15 dollar' )
age = int ( input ( 'your age?' ))

#7-6
s = input ( '给我们些披萨配料!' )
while s != 'quit' :
print ( 'we will add %s to it' % s)
s = input ()
while True :
s = input ( '给我们些披萨配料!' )
if s == 'quit' :
break
else :
print ( 'we will add %s to it' % s)

active = True
while active :
s = input ( '给我们些披萨配料!' )
if s == 'quit' :
active = False
else :
print ( 'we will add %s to it' % s)



#7-7
while True :
print ( 1 )

#7-8
sandwich_orders = [ '奶酪三明治' , '海鲜三明治' , '火腿三明治' ]
finished_sandwiches = []
while sandwich_orders :
s = sandwich_orders.pop()
print ( ' %s have finished' % s)
finished_sandwiches.append(s)

#7-9
sandwich_orders = [ '奶酪三明治' , '海鲜三明治' , '火腿三明治' , 'pastrami' , 'pastrami' , 'pastrami' ]
print ( 'we are out of pastrami' )
while 'pastrami' in sandwich_orders:
sandwich_orders.remove( 'pastrami' )

#7-10
place = input ( 'If you could visit one place in the world, where would you go?' )

print ( 'pass quit to quit' )
answer = {}
while place != 'quit' : -
if place in answer.keys():
answer[place] += 1
else :
answer[place] = 0
place = input ( 'If you could visit one place in the world, where would you go?' )
for i,v in answer.items():
print ( 'place: ' ,i, 'number: ' ,v)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值