[SYSU][大二下] 高级编程技术HW Week-4 Lecture-1

Question

教材中课后的练习,7-1到7-10,选一些写到你的博客上


Answer

''' 
SYSU - [专选]高级编程技术 - Week4, Lecture1 HW    
by Duan    
2018.03.26   
'''    


'''
7-1 汽车租赁
'''
car = input('What kind of car would you like? ')
print('Let me see if I can find you a', car)
#Input:
# BMW
#Output:
# What kind of car would you like? BMW
# Let me see if I can find you a BMW


'''
7-2 餐馆订位
'''
num = input('How many people are going to have dinner here? ')
num = int(num)
if num > 8:
    print("We don't have enough table for all of you.")
else:
    print("We have enough table for you.")
#Input:
# 4
#Output:
# How many people are going to have dinner here? 4
# We have enough table for you.


'''
7-5 电影票
'''
while 1:
    age = input("How old are you? ")
    age = int(age)
    if age < 3:
        print('You can watch movie for free.')
    elif age <= 12:
        print('You should pay $10 for the movie.')
    elif age > 12:
        print('You should pay $15 for the movie.')
#Input:
# 2
# 10
# 19
#Output:
# How old are you? 2
# You can watch movie for free.
# How old are you? 10
# You should pay $10 for the movie.
# How old are you? 19
# You should pay $15 for the movie.


'''
7-8 熟食店
'''
sandwich_orders = ['J sandwich', 'tuna sandwich', 'beef sandwich']
finished_sandwiches = []
while len(sandwich_orders) != 0:
    print('I made your', sandwich_orders[0])
    finished_sandwiches.append(sandwich_orders.pop(0))
print('\n---- ALL FINISHED ----')
for sandwich in finished_sandwiches:
    print(sandwich)
#Output:
# I made your J sandwich
# I made your tuna sandwich
# I made your beef sandwich

# ---- ALL FINISHED ----
# J sandwich
# tuna sandwich
# beef sandwich


'''
7-9 五香烟熏牛肉(pastrami)卖完了
'''
print('---- NOTICE ----')
print('Pastrami sandwiches have been all sold out.\n')
sandwich_orders = ['J sandwich', 'pastrami sandwich', 'tuna sandwich', 
    'pastrami sandwich','beef sandwich', 'pastrami sandwich']
while 'pastrami sandwich' in sandwich_orders:
    sandwich_orders.remove('pastrami sandwich')
    
finished_sandwiches = []
while len(sandwich_orders) != 0:
    print('I made your', sandwich_orders[0])
    finished_sandwiches.append(sandwich_orders.pop(0))
print('\n---- ALL FINISHED ----')
for sandwich in finished_sandwiches:
    print(sandwich)
#Output:
# ---- NOTICE ----
# Pastrami sandwiches have been all sold out.

# I made your J sandwich
# I made your tuna sandwich
# I made your beef sandwich

# ---- ALL FINISHED ----
# J sandwich
# tuna sandwich
# beef sandwich


'''
7-10 梦想的度假胜地
'''
active = True
places = {}
while active:
    name = input("What's your name? ")
    place = input("If you could visit one place in the world, where would you go? ")
    places[name] = place
    repeat = input("Would you like to let another person respond?)(Y/N)")
    if repeat == 'N':
        active = False

print('\n--- Poll Results ---')
for name, place in places.items():
    print(name.title(), 'would like to visit', place.title())
#Input:
# Peter Parker
# New York
# Y
# Steven Rogers
# Russia
# N
#Output:
# What's your name? Peter Parker
# If you could visit one place in the world, where would you go? New York
# Would you like to let another person respond?)(Y/N)Y
# What's your name? Steven Rogers
# If you could visit one place in the world, where would you go? Russia
# Would you like to let another person respond?)(Y/N)N

# --- Poll Results ---
# Peter Parker would like to visit New York
# Steven Rogers would like to visit Russia

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值