【发布时间】:2022-01-10 00:59:11
【问题描述】:
File "solution.py", line 12
Rate=8.45 and S=75 and D=tempUnit-150
^
SyntaxError: can't assign to operator
完整代码:
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")
伙计们,我无法解决这里的问题。只是 python 的初学者,将不胜感激。
【问题讨论】:
-
请分享更多详细信息,例如涉及的代码以及您解决问题的尝试。另外,请标记您正在使用的编程语言
-
and 的目的是什么?你想执行所有三个任务吗?你可以用分号替换and。
-
@Mark 或将它们放在单独的行上。
-
@Ishan,为什么您认为
Rate = 2.60 and S = 25是将这些值分配给这些变量的正确方法?and是布尔运算符,而不是行分隔符。 -
我想我只是个笨蛋
标签: python syntax-error assignment-operator