Pythonのチャレンジ25Pythonの挑戦25:書き込みファイル
放課後のクラブのためにサインアッププログラムを書きます。それは次の詳細をユーザーに尋ねると、ファイルに保存する必要があります
- 名姓が
- は、上記の課題については性別
- フォーム
私が書いた
# Python Challenge 25
print ("Hello user, this is a virtual application form"
"\nfor joining after-school clubs at -Insert school name here-")
first_name = input("\n\nPlease input your first name:")
last_name = input("Please input your last name:")
gender = input("Please input your gender:")
form = input("Please input your form name:")
club = input("What after-school club would you like to attend?\n")
file = open("application-form.txt", "w")
file.write(first_name)
file.write (last_name)
file.write (gender)
file.write (form)
file.write (club)
file.close()
print (first_name, "Thank you for taking your time to fill this virtual form"
"\nall the information has been stored in a file to maintain confidentiality")
例o上記のコードの結果F:
私の質問
テキストファイルは、すべてのユーザー入力を保存するが1行に格納され、私の方法があります各入力を別々の行に置くことができますか?
上記のコードを書くより効率的な方法はありますか?
より効率的にすると、短いコードを意味するのか、より速く実行するのでしょうか? –
より短いコード。 – Hackers45