练手例子_main函数、调用其他函数、输入字符保存

# hello3.py
import hello4

person = {'Alice': 13, 'Bob': 35, 'May': 56, 'Lin': 29}
body_name = ['head', 'body', 'hand', 'leg', 'foot']


# 找出想要的字符串
def number_name():
n = int(input('Input a number:\n'))
if 0 < n < 5:
print(body_name[n])
else:
print("Please input a number in 0 and 4")
hello4.get_time()


# 找出年纪最大的人
def age_old():
p_name = 'Alice'
for key in person.keys():
if person[p_name] < person[key]:
p_name = key
print('%s,%d', (p_name, person[p_name]))


# 保存所有输入的字符串到test.txt文件中
def save_text():
fp = open('text.txt', 'w')
string = input('Please input a string:\n')
fp.write(string)
fp.closed


# __name__ == “__main__” 作为启动py文件的main函数入口
if __name__ == "__main__":
save_text()
posted @ 2020-04-13 19:00  lihuimin222  阅读(346)  评论(0编辑  收藏  举报