#8-1
def display_message():
print('Function!!!')
display_message()
display_message()
display_message()
#8-2
def favorite_book(title):
print(title + ' is my favourite book!!')
favorite_book('Dark')
favorite_book('Fantasy')
#8-3
def make_shirt(size, word):
print('Shirt`s size is: ' + str(size) + ', and "' + word + '" will be print on the shirt.')
make_shirt(100,'fantasy')
#8-4
def make_shirt(size, word = 'I love Python'):
print('Shirt`s size is: ' + str(size) + ', and "' + word + '" will be print on the shirt.')
make_shirt(50)
make_shirt(100)
make_shirt(100,'fantasy')
#8-5
def describe_city(city, country = 'China'):
print(city.title() + ' is in '+ country.title() + '.')
describe_city('Shanghai')
describe_city('Beijing')
describe_city('Tokyo','Japan')
#8-6
def city_country(city, country):
re = '"' + city.title() + ', ' + country.title() + '"'
return re
print (city_country('Sahanghai','China'))
print (city_country('Santiago','chile'))
print (city_country('Tokyo','Japan') )
#8-7
def make_album(singer,alb,sings = 0):
re = {
'name': singer,
'album': alb,
}
if sings > 0:
re['amount'] = sings
return re
print( make_album('n1','a1'))
print( make_album('n2','a2'))
print( make_album('hello','hjaa',20))
#8-8
def make_album(singer,alb,sings = 0):
re = {
'name': singer,
'album': alb,
}
if sings > 0:
re['amount'] = sings
return re
while True:
name = input('Input the singer`s name: ')
album = input('Input his album `s name: ')
print(make_album(name,album))
q = input('Do you want toi add one more item?(y/n)')
if q == 'n':
break
#8-9
def show_magicans(magicans):
for magican in magicans:
print(magican)
magicans = ['Ti','Ben','Ann']
show_magicans(magicans)
#8-10
def show_magicans(magicans):
for magican in magicans:
print(magican)
def make_great(magicans):
l = len(magicans)
for i in range(l):
magicans[i] = 'the Great ' + magicans[i]
magicans = ['Ti','Ben','Ann']
make_great(magicans)
show_magicans(magicans)
#8-11
def show_magicans(magicans):
for magican in magicans:
print(magican)
def make_great(magicans):
l = []
while magicans:
current = magicans.pop()
l.append('the Great ' + current)
return l
magicans = ['Ti','Ben','Ann']
show_magicans(make_great(magicans[:]))
show_magicans(magicans)
#8-12
def add(*foods):
print('Your sandwich include: ')
for food in foods:
print(food)
add('1','2','3')
add('tomato','potato')
add('chcken')
#8-14
def make_car(maker, typ, **other):
car = {}
car['maker'] = maker
car['type'] = typ
for key,val in other.items():
car[key] = val
return car
car = make_car('subaru','outback',color = 'blue', tow_package=True)
print(car)