如何通过输入使值正确或错误?

问题描述 投票:0回答:1

我知道我应该可以自己解决这个问题,但是我该如何简单地编写一个根据输入改变某些值的代码。这是我的代码;

`

a = False
c = input("do you want A to be positive or negative?\n")

if c== "Pos" or "pos":
    print("a switched to positive")
    a = True

if c== "Neg" or "neg":
    print("a switched to negative")
    a = False

`虽然不行。我该怎么做?谢谢!

python input
1个回答
0
投票

您的python语法错误。签入条件时,代替

if c == "Pos" or "pos"

您应该有,

if c == "Pos" or c == "pos"
© www.soinside.com 2019 - 2024. All rights reserved.