高级编程技术第四周作业

本文通过多个实际案例展示了Python编程的基础语法及应用,包括条件判断、循环结构、列表操作、函数定义等核心概念。通过这些示例,读者可以更好地理解并掌握Python编程的基本技巧。

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

7.2

amount=int(input("How many people come to eat? "))
if amount>8:
	print("There is no empty table")
else:
	print("There is a empty table")

7.3

amount=int(input("Please input a number and i'll figure out whether is the mutiples of 10: "))
if amount%10==0:
	print("It is "+str(int(amount/10))+" times of 10")
else:
	print("It isn't the mutiple of 10")
7.5
age=int(input("How old are you? "))
while 1:
	if age < 3:
		print("It's free.")
	elif age<=12:
		print("It's $10.")
	else:
		print("It's $15.")
	age=int(input("How old are you? "))

7.6

age=(input("How old are you? "))
active=True
while active:
	if age=="quit":
		break
	elif int(age) < 3:
		print("It's free.")
	elif int(age)<=12:
		print("It's $10.")
	else :
		print("It's $15.")
	age=input("How old are you? ")

7.8

sandwich_orders=['tuna','pastrami','reuben','italian','meatball','sloppy']
finished_sandwiches=[]
while sandwich_orders:
	sandwich=sandwich_orders.pop()
	print("I made your "+sandwich+" sandwich")
	finished_sandwiches.append(sandwich)
print("I've made sandwich of these kinds:")
print(finished_sandwiches)
7.9
print("Our pastrami have been sold out.")
sandwich_orders=['tuna','pastrami','reuben','pastrami','italian','meatball','pastrami','pastrami','sloppy']
while 'pastrami' in sandwich_orders:
	sandwich_orders.remove('pastrami')
print(sandwich_orders)

8.2

def favorite_book(title):
	print("One of my favorite books is "+title+'.')
favorite_book("Harry Potter")

8.4

def make_shirt(size,message="I love Python"):
	print("'"+message+"' was printed on the "+size+" shirt")
make_shirt('large')
make_shirt('middle')
make_shirt('small',"Hello world")
8.8
def make_album(person,album,songs=-1):
	if songs==-1:
		album={'person':person,'album':album}
	else:
		album={'person':person,'album':album,'songs':songs}
	return album
while 1:
	person=input("What's the singer's name: ")
	if person =='quit':
		break
	album=input("What's the album's name: ")
	songs=int(input("How many songs in this album(If you don't konw,please input -1): "))
	album=make_album(person,album,songs)
	print(album)

8.10

def show_magicians(magicans):
	for magican in magicans:
		print(magican)
def make_great(magicans):
	new_magicans=[]
	for magican in magicans:
		new_magicans.append("the Great "+magican)
	while magicans:
		magicans.pop()
	for magican in new_magicans:
		magicans.append(magican)
magicans=['Bob','Ann','Harry','Terry','Kane']
show_magicians(magicans)
make_great(magicans)
show_magicians(magicans)
8.14
def make_car(producer,model,**info):
	car={}
	car['producer']=producer
	car['model']=model
	for key,value in info.items():
		car[key]=value
	return car
car=make_car('subaru','outback',color='blue',tow_package=True)
print(car)
car=make_car('toyota','outback',color='black',tow_package=False,money=300000,highest_speed=220)
print(car)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值