0
我刚刚完成我的家庭作业作家的程序,现在我有一个非常恼人的问题为什么我不能在python中重新运行一个函数?
我做到了,所以当一个函数完成它询问是否要重新运行的主要功能,当我这样做,那么运行不同的功能(对不起,如果我吮吸措辞的东西)该功能什么也没有。有什么我可以做的吗?
这里是我的代码
agenda=open("agenda.txt","a") #open the notepad file
def choice(): #pick the period
choice=input("type write, read, or clear\n")
if choice=="read":
read()
elif choice=="write":
write()
elif choice=="clear":
clear()
else:
print("Invalid Choice")
def write(): #write the homework
per=input("What period is it")
hw=input("What is the homework")
if per=="1":
agenda.write("Period 1:")
agenda.write(hw)
agenda.write("\n")
elif per=="2":
agenda.write("Period 2:")
agenda.write(hw)
agenda.write("\n")
elif per=="3":
agenda.write("Period 3:")
agenda.write(hw)
agenda.write("\n")
elif per=="4":
agenda.write("Period 4:")
agenda.write(hw)
agenda.write("\n")
elif per=="5":
agenda.write("Period 5:")
agenda.write(hw)
agenda.write("\n")
elif per=="6":
agenda.write("Period 6:")
agenda.write(hw)
agenda.write("\n")
elif per=="7":
agenda.write("Period 7:")
agenda.write(hw)
agenda.write("\n")
elif per=="8":
agenda.write("Period 8:")
agenda.write(hw)
agenda.write("\n")
else:
print("Non existant period")
again=input("Would you like to read the homework, clear, or read again? (yes or no)")
if again=="yes":
choice()
elif again=="no":
print("\n")
def clear():#clear the whole thing
ajenda = open('agenda.txt', 'r+')
ajenda.truncate()
again=input("Would you like to read the homework, clear, or read again? (yes or no)")
if again=="yes":
choice()
elif again=="no":
print("\n")
def read():#read the homework
read=open("agenda.txt","r")
readf=read.read()
print(readf)
read.close
again=input("Would you like to read the homework, clear, or read again? (yes or no)")
if again=="yes":
choice()
elif again=="no":
print("\n")
choice()
agenda.close()
程序的输出以及预期结果可能会有所帮助。 – 2012-01-15 04:12:19
我想你想使用raw_input()而不是input() – 2012-01-15 04:13:18
@VaughnCato:raw_input在python 3中不见了。 – 2012-01-15 08:35:31