SYSU Python 第四周作业

本文通过一系列Python编程实例,展示了如何处理用户输入、制作三明治、完成调查问卷等常见任务,并介绍了基本的函数定义与使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#7.1
car=input("Please input the car you want to rent: ")
print("Let me see if I can find a",car,"for you")
#7.2
num=int(input("Please input the num of guests: "))
if num>8:
   print("no")
else:
   print("yes")
#7.3
num=int(input())
if num%10==0:
    print("yes")
else:
    print("no")

#7.4
print("Please input a list of ingredients")
ing=input()
while ing!="quit":
    print("We'll add",ing)
    ing=input()
#7.7
while 2==1:
    print("infinite")

#7.8
sandwich_order=['A','B','C','D']
finished_sandwiches=[]
while sandwich_order:
    current=sandwich_order.pop(0)
    print("I made your",current,"sandwich")
    finished_sandwiches.append(current)
print("Finished list:",finished_sandwiches,sep='\n')
#7.10
responses={}
act=True
while act:
    name=input("What's your name ")
    responses[name]=input("If you could visit one place in the world, where would you go: ")
    print()
    repeat=input("If anyone else want to response (Y/N)")
    print()
    if repeat=="N":
        break
print("\n------results------")
for name,response in responses.items():
    print(name,"would like to go to",response)

#8.1
def display_message():
    print("I'v learned functions")
display_message()

#8.4
def make_shirt(size='big',word='I love python'):
    print(size,word)
make_shirt()
make_shirt('small','a')

#8.7
def make_album(name,album):
    a={}
    a['name']=name
    a['album']=album
    return a
print(make_album('Singer A','Album A'))
print(make_album('Singer B','Album B'))
print(make_album('Singer C','Album C'))

#8.9-8.10
magician=['A','B','C']
def show_megicians(name):
    for names in name:
        print(names)
show_megicians(magician)
def make_great(name):
    length=len(name)
    for i in range(length):
        name[i]="The great "+name[i]
make_great(magician)
print(magician)

#8.12
def make_sandwich(*ingredients):
    print("\nMaking a sandwich with the following ingredients:")
    for ings in ingredients:
        print('  -'+ings)
make_sandwich('Tuna','Tomato','sause')
make_sandwich('Steak','Tomato','sause')
make_sandwich('Bacon','sause')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值