Search code examples
python-3.xloopsif-statementpycharm

Two variables with different values and IF statement isn't working on them if in the same loop


Okay, lets say I have three variables with different values, taking input from the user, and if input equals say variable a then print variable b in a string. I can't see a code to do this but if I use or for the two variables in the is statement it work. See code below


Solution

  • I'm just going to give a basic structure as there is no code given, you can modify according to your problem.

    a = 1
    b = 2
    c = 3
    val = int(input('Enter a number'))
    if val == a:
        print(b)
    elif val == b:
        print(c)
    else:
        print(b)