您的位置:首页 > 编程语言 > Python开发

《Python编程-从入门到实践》第七章及第八章习题训练

2018-03-31 20:42 501 查看
7-310的整数倍:num = int(input("Input a num:"))
if (num % 10) == 0:
print("yes")
else:
print("no")7-4披萨配料:a = True
while a != "quit":
a = input("wut do you want?")
if a != 'quit':
print("we will add " + a)7-8熟食店:sandwich_orders = ["a", 'b', 'c']
finished_sandwich = []
while sandwich_orders:
a = sandwich_orders.pop()
print("we made " + a)
finished_sandwich.extend(a)
print(finished_sandwich)8-2喜欢的图书:def favorite_book(book):
print("my favorite book is " + book)
favorite_book('AA')8-4大号T恤:def make_shirt(size,word = 'I love python'):
print("a " + size + ' tshirt is made with ' + word + ' on it')
make_shirt(size = 'large')
make_shirt(size = 'medium')
make_shirt(word='a',size='small')8-7专辑:def make_album(n1,n2,number = 0):
album = {'artist' : n1, 'album' : n2}
if number != 0:
album['number'] = int(number)
return album
print(make_album('a','A'))
print(make_album('b','B'))
print(make_album('c','C',2))8-11不变的魔术师:magicians = ["a A", 'b B', 'c C']
great_magicians = []

def make_great(list1, list2):
while list1:
a = list1.pop()
a = a + ' the great'
print(a)
list2.append(a)
print(list2)

make_great(magicians[:],great_magicians)8-12三明治:def sandwich(*material):
san = []
for m in material:
san.extend(m)
print(san)

sandwich('a','b','c')
sandwich('a','b')
sandwich('a')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: