7-3 10的整数倍:
# -*- coding: utf-8 -*- number = int (input('请输入一个数:')) if number % 10==0: print ('数字' + str(number) + '是10的整数倍') else : print ('数字' + str(number) + '不是10的整数倍')7-6 三个出口:
while True: age = input('Please input your age: ') if age =='quit': break age = int(age) if age < 3: price = 0 elif age < 12: price = 10 else : price = 15 print ('Your should pay $' + str(price) + ' for the ticket.\n')7-10 梦想的度假胜地:
responses = {} polling_active = True while polling_active: name = input ('\nWhat is your name? ') place = input ('If you could visit one place in the world, where would you go?') responses[name]= place repeat = input ('Would you like to let another person respond?(yes / no) ') if repeat =='no': polling_active =False print ('\n------Poll Result------') for name, place in responses.items(): print (name + ' would like to go to ' + place + '.')
8-5 城市:
def describe_city(city, country= 'China'): print (city.title() + ' is in ' + country.title() + '.') describe_city('Guangzhou') describe_city(city = 'nagoya', country = 'japan') describe_city(country = 'england', city = 'london')8-10 了不起的魔术师:
lists = ['Mike', 'Tony', 'Chris'] def show_magicians(magicians): for magician in magicians: print (magician.title() + '.') def make_great(magicians): for i in range(0, len(magicians)): magicians[i] = 'the Great ' + magicians[i] show_magicians (lists) make_great(lists) show_magicians(lists)8-12 三明治:
def make_sandwich(*toppings): print ('Making a sandwich with the following toppings: ') for topping in toppings : print ('-' + topping) print ('\n') make_sandwich('egg', 'cheese', 'ham') make_sandwich('egg', 'beef') make_sandwich('vegetables', 'cheese', 'ham')