第四周第一次作业

7-1 汽车租赁

Car=input("What do you want to rent a car?\n")
print('Let me see if I can find you a ',Car)

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
What do you want to rent a car?
Mercedes-Benz
Let me see if I can find you a  Mercedes-Benz

Process finished with exit code 0

7-2 餐馆订位

number=input("How many people to have meal ?\n")
number=int(number)
if(number>8):
    print("Sorry! No free table!")
else:
    print("We have free table")

Output 1:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
How many people to have meal ?
9
Sorry! No free table!

Process finished with exit code 0

Output 2:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
How many people to have meal ?
1
We have free table

Process finished with exit code 0

7-5 电影票

message="Please enter your age (Enter 'quit' to quit): "
while (True):
    Age=input(message)
    if(Age=='quit'):
        break;
    Age=int(Age)
    if(Age<3):
        print("Free")
    elif(Age<13):
        print("Ten dollars")
    else:
        print("Fifteen dollars")

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
Please enter your age (Enter 'quit' to quit): 1
Free
Please enter your age (Enter 'quit' to quit): 8
Ten dollars
Please enter your age (Enter 'quit' to quit): 18
Fifteen dollars
Please enter your age (Enter 'quit' to quit): quit

Process finished with exit code 0

7-6 三个出口

message="Please enter your age (Enter 'quit' to quit): "
Active=True
while (Active):
    Age=input(message)
    if(Age=='quit'):
        break;
    Age=int(Age)
    if(Age<3):
        print("Free")
    elif(Age<13):
        print("Ten dollars")
    else:
        print("Fifteen dollars")

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
Please enter your age (Enter 'quit' to quit): 1
Free
Please enter your age (Enter 'quit' to quit): 4
Ten dollars
Please enter your age (Enter 'quit' to quit): 20
Fifteen dollars
Please enter your age (Enter 'quit' to quit): quit

Process finished with exit code 0

7-8 熟食店

sandwich_orders=['beef','chicken','tuna']
finished_sandwiches=[]
print('sandwich_orders:',end='')
print(sandwich_orders)
while sandwich_orders:
    sandwich=sandwich_orders.pop()
    finished_sandwiches.append(sandwich)
    print("I made your",sandwich,'sandwich')
print('finished_sandwiches:',end='')
print(finished_sandwiches)

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
sandwich_orders:['beef', 'chicken', 'tuna']
I made your tuna sandwich
I made your chicken sandwich
I made your beef sandwich
finished_sandwiches:['tuna', 'chicken', 'beef']

Process finished with exit code 0

7-9 五香烟熏牛肉卖完了

sandwich_orders=['pastrami','beef','pastrami','chicken','tuna','pastrami']
print("Original:",sandwich_orders)
print("Sorry!The pastrami sandwich has sold out!")
while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')
print("New:",sandwich_orders)

Output:

/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
Original: ['pastrami', 'beef', 'pastrami', 'chicken', 'tuna', 'pastrami']
Sorry!The pastrami sandwich has sold out!
New: ['beef', 'chicken', 'tuna']

Process finished with exit code 0












  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值