[英]How can I fix 'Statement seems to have no effect' error?
任務是讓用戶輸入一些值,如果花了額外的現金來代替基本商品,但是如果沒有花額外的現金,那么我希望程序繼續進行下一行代碼。
我的代碼哪里出錯了?
print("Did you spend extra to replace a capital goods\n")
variableExpense = 'Yes'
variableExpense = 'No'
if variableExpense == 'Yes':
variableExpense = input('How much did you spent: \n')
else:
if variableExpense == 'No':
print('print some statement.\n')
當前,您正在將variableExpense
分配給值Yes
,然后在下一行中將其設置為No
,因此, if variableExpense == 'Yes'
的以下語句將永遠不會得出true。 像這樣嘗試
print("Did you spend extra to replace a capital goods\n")
variableExpense = input("Yes or No: ")
if variableExpense.lower() == 'yes':
extraSpent = input('How much did you spent: \n')
else:
if variableExpense.lower() == 'no':
print('print some statement.\n')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.