if __name__ == '__main__':
fp = open('test.txt','w')
string = input('please input a string:\n')
string = string.upper()
fp.write(string)
fp = open('test.txt','r')
print (fp.read())
fp.close()
给每一行代码用中文注释下 要求简洁明了 然后把整个代码(包括注释)发我
if __name__ == '__main__':# 判断模块是不是作为主程序运行
fp = open('test.txt','w')# 用写的方式打开文件test.txt,并将文件对象赋值给fp
string = input('please input a string:\n')# 交互式等待输入,将输入内容赋值给string
string = string.upper()# 将string所有内容全变为大写
fp.write(string)# 通过上面打开的文件对象将string写入文件test.txt
fp = open('test.txt','r')# 用读的方式打开文件test.txt并将文件对象赋值给fp
print (fp.read())# 读出文件中所有的内容并输出到屏幕
fp.close()# 关闭文件