[英]Python 3.4: How do I assign variables to operators?
我正在尝试创建一个快速程序,该函数将对多项式进行综合除法运算,但是当我尝试执行代码时,它会告诉我R * A:无法分配给运算符。 我认为这意味着它不能执行乘法运算,但是为什么呢? 我在编程方面的经验有限,仅使用Java CompSci一年
print("This program assumes that the polynomial is to the 4th degree")
A = input('Input the first coefficient: ')
B = input('Input the second coefficient: ')
C = input('Input the third coefficient: ')
D = input('Input the fourth coefficient: ')
E = input('Input constant: ')
R = input('Input the divisor: ')
temp = 0
R*A = temp
#B + temp = temp
#R * temp = temp
#C + temp = temp
#R * temp = temp
#D + temp = temp
#R * temp = temp
#E + temp = temp
if temp == 0:
print("It works!")
else:
print("dang")
input('This is a shitty workaround for pause')
我假设您不是在尝试重新分配运算符,而只是在做乘法。
与其他许多语言(包括Java)一样,在python中,分配是这样完成的:
temp = R*A
温度= R * A
您的输入将为str。 您需要告诉python这将是一个int。 int(input(“ ....”))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.