简体   繁体   English

如何解决“声明似乎无效”错误?

[英]How can I fix 'Statement seems to have no effect' error?

The mission is to get the user to input some value if extra cash was spent to replace a capital good, but if no extra cash was spent, then I want the program to move on to the next line of code. 任务是让用户输入一些值,如果花了额外的现金来代替基本商品,但是如果没有花额外的现金,那么我希望程序继续进行下一行代码。

Where did I go wrong with my code? 我的代码哪里出错了?

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')

You are currently assigning variableExpense to the value Yes , then in the next line you set it to No , so the following statement if variableExpense == 'Yes' will never evaluate to true. 当前,您正在将variableExpense分配给值Yes ,然后在下一行中将其设置为No ,因此, if variableExpense == 'Yes'的以下语句将永远不会得出true。 Try it like this 像这样尝试

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM