用python来完成
以自己学号为文件名,存放自己姓名,性别,籍贯信息,这些信息各占一行。 字典嵌套 #coding:gbkdef foo(s):
r = ''
while not r:
r = input(s) . strip()
return r
id = input('你的学号:') . strip()
if id :
name = foo('你的姓名:')
sex = foo('你的性别:')
htown = foo('你的籍贯:')
fn = id + '.txt'
with open(fn , 'wt' , encoding = 'GBK') as fp:
fp . write(name + '\n')
fp . write(sex + '\n')
fp . write(htown + '\n')
print('信息已经记入文件[' + fn + '].') def write_data(studyNum, name, sex, place):
with open(studyNum,"w") as file:
file.write(name + "\n")
file.write(sex + "\n")
file.write(place + "\n")
return "写入成功"
def main():
studyNum = input("请输入你的学号:")
name = input("请输入你的姓名:")
sex = input("请输入你的性别:")
place = input("请输入你的籍贯:")
resalut = write_data(studyNum, name, sex, place)
print(resalut)
if __name__ == '__main__':
main()
页:
[1]