2012-01-15 3 views
0

방금 ​​숙제 작가 프로그램을 마쳤으며 이제는 정말 귀찮은 문제가 생겼습니다.왜 파이썬에서 함수를 다시 실행할 수 없습니까?

기능을 마치면 주 기능을 다시 실행할지 묻는 메시지가 나타납니다. 미안 내가 말씨 것들을 빨아) 함수는 전혀 아무것도하지 않습니다. 내가 할 수 있는게 있습니까?

여기에 내가 지금 python3이 없기 때문에 내가 python2.7에서 코드를 실행 내 코드

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() 
+0

예상 결과와 함께 프로그램을 출력하면 도움이 될 수 있습니다. –

+0

input() 대신 raw_input()을 사용하려고한다고 생각합니다. –

+2

@VaughnCato : raw_input은 python 3에서 사라졌습니다. –

답변

2

입니다.

내 생각에 코드를 실행하고 숙제를 작성한 다음 읽고 읽으라는 메시지가 표시됩니다. 성능상의 이유로 파일에 쓸 때 특정 양의 데이터가 제공되거나 파일을 닫을 때까지 버퍼에 파일이 들어 가지 않습니다.

코드를 테스트 한 다음 프로그램을 종료하면 파일에서 데이터를 찾을 수 있습니다. write 메소드에 flush() 호출을 추가하는 것을 고려할 수 있습니다.

관련 문제