import CSV
file_name = input("PLease type in a file name including the extension e.g. .docx or .txt\nelse:")
start = 0
error = 0
with open(file_name, newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=' ', quotechar='|')
answer = input("Do you want all information to be displayed or only part of it?(A/P)")
answer = answer.upper()
print(answer)
if answer == "A" or "a":
All_Info()
elif answer == "P" or "p":
Part_Info()
else:
if error < 2:
error = error + 1
answer = input("Please only type in A or P")
當我嘗試運行該程序並在鍵入csv文件名後按p鍵時忽略了elif並直接轉到if語句,請幫忙!爲什麼我的if/elif/else不工作?
因爲你轉換爲大寫,你可以做'如果答案=='A「':那會很好的... –
@ Jean-FrançoisFabre難道你沒有這個笨蛋嗎? –
是的,但問題被標記爲pytho 3.x只。我編輯爲python。我希望我有一個python 3.x標籤dupehammer! –