これは、学生の詳細を入力するためのコードです。ユーザが詳細を入力してyesを入力すると、詳細はStudentDetails.csv(Microsoft Excel)にエクスポートされ、そこでヘッダーの下に移動する必要がありますが、別の場所に移動します。ユーザーが入力したデータをヘッダーの下に表示する方法
def EnterStudent():
uchoice_loop = False
ask_loop = False
while uchoice_loop == False:
surname = raw_input("What is the surname?")
forename = raw_input("What is the forname?")
date = raw_input("What is the date of birth? {Put it in the format D/M/Y}")
home_address = raw_input("What is the home address?")
home_phone = raw_input("What is the home phone?")
gender = raw_input("What is their gender?")
tutor_group = raw_input("What is their tutor group?")
email = (forename.lower() + surname.lower() + ("@school.com"))
print(surname+" "+forename+" "+date+" "+home_address+" "+home_phone+" "+gender+" "+tutor_group+" "+email)
ask = raw_input("Are these details correct?"+"\n"+"Press b to go back, or yes to add entered data on your student.").lower()
if ask == "yes":
f = open("StudentDetails.csv","rt")
lines = f.readlines()
f.close()
lines.append(surname+","+forename+","+date+","+home_address+","+home_phone+","+gender+","+tutor_group+","+email+"\n")
f = open("StudentDetails.csv", "w")
f.writelines(lines)
f.close()
uchoice_loop = True
printMenu()
elif ask == "b":
uchoice_loop = False
else:
print("Plesase enter 'b' to go back or 'yes' to continue")
これは私のCSVファイルです。 enter image description here
ようこそスタックオーバーフロー!少し詳しい情報を提供するために投稿を編集してください。代わりにデータはどこに行くのですか?どのようなエラーメッセージが表示されますか?これは私たちがあなたを助けるのに役立ちます。 – meenaparam