高級編程技術,第四周

7-1

name = input("Which car do you want to rent?:")
print("Let me see if I can find you a " + name)

7-2

num = input("How many people are there?:")
if int(num) > 8 :
	print("There is no free table!")
else:
	print("There is  free table!")
7-3
num = input("Please enter a num:")
if int(num) % 10 == 0:
	print("It's a multiple of 10.")
else:
	print("It's not a multiple of 10.")

7-4

prompt = "Tell me What do you want to add in pizza?:"
prompt += "\nEnter 'quit' to end the prog"
print(prompt)
mess = ""
while mess != 'quit':
		mess = input()
		if mess != 'quit':
			print("We'll add " + mess)

7-7

while 1 < 2 :
	print("hoverwings!")
	

7-8

sandwich_orders = ['Egg Mayo', 'Prawn Mayo', 'Tuna Mayo', 'BLT']
finish_sandwich = []

while sandwich_orders:
	current = sandwich_orders.pop()
	print("I made your " + current + " sandwich.")
	finish_sandwich.append(current)
	

for f in finish_sandwich:
	print(f)

============================================================================

8-1

def display_message():
	print("I'M LEARNING FUNCTION")
	
display_message()

8-2

def f_book(book):
	print("One of my favorite books is " + book)
	
f_book("HarryPotter")

8-3

def make_shirt(word, size):
	print("\nThe T-Shirt is " + str(size) + "size.")
	print("There is '" + word + "' on it.")
	
make_shirt("I'm lovin' it", 38)
make_shirt(size = 38, word = "I'm lovin' it")

8-4

def make_shirt(size,word = 'I Love Python'):
	print("\nThe T-Shirt is " + str(size) + "size.")
	print("There is '" + word + "' on it.")
	
make_shirt(38)
make_shirt(35)
make_shirt(38,"3 1 5 4!")

8-6

def city_country(city,country):
	return city.title() + ' ' + country.title()
	
print(city_country('changsha','china'))
print(city_country('milan','italy'))
print(city_country('tokyo','japan'))

8-7

def make_album(s,n):
	album = {'singer':s, 'name':n}
	return album

print(make_album('lady gaga', 'The Fame'))
print(make_album('katy perry', 'PRISM'))
print(make_album('OOR', 'Ambitions'))

8-9

def show_magicians(magic):
	for m in magic:
		print(m)
		
magicians = ['David','Liuqian','EE']
show_magicians(magicians)

8-10

def show_magicians(magic):
	for m in magic:
		print(m)
		
def make_great(magic):
    for i in range(len(magic)):
        magic[i]='The Great '+magic[i]


magicians = ['David','Liuqian','EE']
show_magicians(magicians)
make_great(magicians)
show_magicians(magicians)

8-12

def make_pizza(*toppings):
	print("We'll add these things")
	for top in toppings:
		print(top)

make_pizza("egg")
make_pizza("egg","bacon")
make_pizza("cheese")

8-14

def make_car(ins, model, **info):
    car = {}
    car['ins'] = ins
    car['model'] = model
    for key, value in info.items():
        car[key] = value
    return car
car = make_car('Ferrai', 'outback', color='red', tow_package=True)
print(car)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章