任务是让用户输入一些值,如果花了额外的现金来代替基本商品,但是如果没有花额外的现金,那么我希望程序继续进行到下一行代码。
>我的代码哪里出错了?
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')
答案 0 :(得分:0)
您当前正在将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')