python习题 要怎么做才好

不知要怎么写了,有点

img

import os
import os.path
def createfile(strPath,strFilename):
name=input("请输入创建的文件夹名字:")
os.mkdir("name")
date=input("请输入源代码:")
with open ("name.py","w") as fp:
fp.write(date)
#在指定的路径下,创建用户指定文件名的Python文件
#并将用户输入的源代码保存到该Python文件中
def revisefile(strPath,strFilename):
with open("strFilename" ,"a+") as fp:
for line in fp.readlines():
list1=[[]]
list1=[line]+list1
while(strPath!=-1):
strPath=input("请输入要修改的行号:")
er=input('请输入新代码:')
list1.remove(strPath)
list1.insert(strPath,er)
fp.write(list1)
#对指定的文件进行修改
#首先显示所有代码(最好能标出行号)(将文件的内容全部读入存放在一个列表中)
#要求用户输入要修改的行号
#然后将用户输入的新的内容,替换掉改行原有的内容
#用户确认修改完后,将列表中的内容写回文件中,并关闭文件
print("1. 创建Python文件")
print("2. 修改Python文件")
print("0. 退出")
intSelect = int(input("请根据操作需要输入对应序号(0-2):"))
while intSelect!=0:
if intSelect==1:
# 创建一个用户指定名称的文件
strFilename=input("请输入要创建的Python文件名:")
strPath=os.getcwd()
createfile(strPath,strFilename)

if intSelect==2:
    # 在当前目录下查找是否存在用户指定的Python文件
    strFilename = input("请输入要修改的Python文件名:")
    strPath = os.getcwd()
    if os.path.exists(strPath+"\\"+strFilename):
        # 如果指定的文件存在,则按照用户的要求进行修改
        revisefile(strPath, strFilename)
    else:
        print("指定的文件不存在")

print("1. 创建Python文件")
print("2. 修改Python文件")
print("0. 退出")
intSelect=int(input("请根据操作需要输入对应序号(0-2):"))

def createfile(strPath,strFilename):
#在指定的路径下,创建用户指定文件名的Python文件
full_path=strPath+'\'+strFilename
file=open(full_path,'a')
#并将用户输入的源代码保存到该Python文件中
content = input("请输入源码(单独输入q结束输入)")
while(content!="q"):
file.write(content+"\n")
content=input()
file.close()
...

def revisefile(strPath,strFilename):
#对指定的文件进行修改
#首先显示所有代码(最好能标出行号)(将文件的内容全部读入存放在一个列表中)
desktop_path=strPath
full_path=desktop_path+'\'+strFilename
file=open(full_path,'r')
contents=file.readlines()
i=1
lines=[]
for line in contents:
print(i,line.rstrip())
lines.append(line)
i=i+1
file.close()
num = int(input("请输入需要修改的行号"))
new_content=input("请输入需要修改的内容")
judge=input("是否确定修改(Y/N)")
if(judge=="Y"):
k = 1
file = open(full_path, 'w')
for line in lines:
if k == num:
file.write('%s\n' %new_content)
k=k+1
else:
file.write('%s' %line)
k = k + 1
file.close()