入力は第2の関数で使用できる最初の関数で収集されますが、すべてをテキストファイルに追加できる必要があります。それはあまりにも多くの議論を言う、助けてください!txtファイルに追加する引数が多すぎます
def newMember(): # gathers info to pass into sub routine to write to file
global surname, year, status, nights, points
print("Please enter the following information")
surname=input("Surname\n")
year=input("Year joined \n")
status=input("Membership status \n")
nights=input("Nights booked \n")
points=input("Points balance \n")
print("Please confirm these details \nSurname: "+surname+ "\nYear joined: "+year+ "\nMembership status: "+status+"\nNights booked: "+nights+ "\nPoints balance: "+points)
reply=input("Please type either Yes or No\n")
if reply in["Y","y","Yes","yes"]: #using an array in the selection to cover possible inputs
print("Thank you, these will now be written to file. Returning you to the main menu options") # write to file
time.sleep(3)
appendMember()
elif reply in ["n","N","no","No"]:
print("Sorry, you will now be prompted to enter the details again")
newMember()
else:
print("I'm sorry, I didn't quite catch that, the program will now restart")
newMember()
def appendMember():
global surname, year, status, nights, points
with open('SampleData2017.txt', mode="a")as crawdale:
crawdale.write[surname, year, status, nights, points]
なぜコードとして貼り付けられないのか分かりません。それは問題である最後の行ですが、姓のようなデータが1つ以上追加されません。 –