0

I know I should probably be able to figure this out on my own, but how do I simply make a code that changes somethings value depending on the input. This is my code:

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

It doesn't work though. How would I do this? Thanks!

shawn
  • 934
  • 1
  • 10
  • 34
damon
  • 83
  • 5

2 Answers2

0

Your python syntax is wrong. When checking in if condition, instead of

if c == "Pos" or "pos"

You should have,

if c == "Pos" or c == "pos"
Prakhar Londhe
  • 1,291
  • 1
  • 10
  • 22
0

One more solution:

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

if "pos" in c.lower():
    print("a switched to positive")
    a = True
elif "neg" in c.lower():
    print("a switched to negative")
    a = False

This will allow user to type "positive" or "negative" both in lower and caps. Also just "pos" and "neg" will be okay.

Neistow
  • 294
  • 1
  • 4
  • 15