Search code examples
pythonsyntax-errorassignment-operator

SyntaxError - can't assign to operator


  File "solution.py", line 12
    Rate=8.45 and S=75 and D=tempUnit-150
        ^
SyntaxError: can't assign to operator

Entire Code:

tempUnit = int(input())
if tempUnit <= 50:
    Rate = 2.60 and S = 25
    print("Electricity Bill =", tempUnit*Rate + S)
elif tempUnit > 50 and tempUnit <= 100:
    Rate = 3.25 and S = 35 and D = tempUnit-50
    print("Electricity Bill =", 50*2.60+D*Rate+S)
elif tempUnit > 100 and tempUnit <= 200:
    Rate = 5.26 and S = 45 and D = tempUnit-100
    print("Electricity Bill =", 50*2.60+50*3.25+D*Rate + S)
elif tempUnit > 200:
    Rte = 8.45 and S = 75 and D = tempUnit-150
    print("Electricity Bill =", 50*2.60+50*3.25+100*5.26+D*Rte + S)
else:
    print("Invalid Input")

Guys, I cannot figure out the problem here. Just a beginner at python an answer would be appreciated.


Solution

  • Seems you're trying to compare values whilst also assigning them. (python does have an operator for this called the walrus operator actually but from the looks of it, it looks like you just want to assign variables values).

    Rte = 8.45 and S = 75 and D = tempUnit-150
    

    has to be

    Rate = 8.45
    S = 75
    D = tempUnit-150
    

    or

    Rate, S, D = 8.45, 75, tempUnit-150