高階程式設計技術第四周作業
阿新 • • 發佈:2019-02-09
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
7.5amount=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")
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
7.9sandwich_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)
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.8def 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.14def 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)