题:设计一个函数:在桌面的文件夹上创建10个文本,以数字给他们命名。
错误代码:
def text_creation():
path='/Users/ASDFGHJKL/Desktop/ppp/'
for name in range(1,11):
with open(path+str(name)+'.txt','w') as text:
text.write(str(name))
text.close()
print('Done')
text_creation()
结果:不报错也不运行,没有打印Done
改后代码:
def text_creation():
path='C:/Users/ASDFGHJKL/Desktop/ppp/'
for name in range(1,11):
with open(path+str(name)+'.txt','w') as text:
text.write(str(name))
text.close()
print('Done')
text_creation()
结果:
仅用于个人学习记录