第七章:input与while
本章主要是介绍了input的输入函数以及while循环控制函数。
7-3
a = int(input('Please input a integer:'))
if (a % 10 == 0):
print('Yes')
else:
print('No')
7-10
survey = {}
i = 0
a = ''
while (a != 'None'):
a = input('Hey #' + str(i) + ', Where?(Input "None" to see result)')
if (a != 'None'):
survey[i] = a
i += 1
for key, item in survey.items():
print(str(key) + ' want to ' + item)
第八章:函数
本章主要讲述了如何定义并使用函数,从而提高代码的可重复利用性。
8-5
def describe_city(cityname, nation='The Sol'):
print(cityname + ' is in ' + nation)
describe_city('Montana', 'USA')
describe_city('Nürnberg', 'Germany')
describe_city('Kuiper belt')
8-13
def build_profile(firstname, lastname, **charis):
print("I'm " + firstname + ' ' + lastname + '.')
for key, item in charis.items():
print('My ' + key + ' is ' + item + '.')
build_profile('A', 'Man', phone_number='never tell you', email_address='something you can guess', something_else='no more')