[英]Python returns error “can't assign to function call”
I keep getting the same error. 我不断收到相同的错误。
This is probably a simple mistake, I just haven't coded in a while. 这可能是一个简单的错误,我只是有一段时间没有编码了。
#import
import math
#initailse variables
float(x1)=0.0
float(y1)=0.0
float(x2)=0.0
float(y2)=0.0
float(complete_y)=0.0
float(complete_x)=0.0
float(final_decimal)=0.0
float(heading)=0.0
#get input
print("Welcome user!")
print("please enter your coordinates in format x and y including
negatives")
x1=input()
y1=input()
print("please enter the coordinates of your target in the format x and y
including negatives, you can obtain these from the map")
x2=input()
y2=input()
print("please hold for calculation")
#calculate
y2-y1==float(complete_y)
x2-x1==float(complete_x)
y/x==float(final_decimal)
math.asin(a)==float(heading)
#output
print("fire at a heading of", heading, "not including the negative if
there is one")`enter code here`
print("press enter to close the programme")
Results in an error 导致错误
expected result is a heading in degrees. 预期结果以度为单位。
My guess is that you are tying to declare the types before assigning values such as : 我的猜测是,您想在分配值之前声明类型:
float(x)=0.0
x = input()
In python, the type is only known at runtime and you cannot declare type of a variable. 在python中,类型仅在运行时已知,并且您不能声明变量的类型。
If you do : 如果您这样做:
x = 0.0
x = input()
print(type(x))
You will see x is a string, because you assigned a string with the input
method. 您会看到x是一个字符串,因为您使用input
法分配了一个字符串。 If you need a float, you need to convert it. 如果需要浮点数,则需要对其进行转换。
x = float(input())
As a side note, 作为旁注,
#calculate
y2-y1==float(complete_y)
This code is valid if y1
, y2
and complete_y
are declared before, it just returns a Boolean, True
or False
. 如果之前声明了y1
, y2
和complete_y
,则此代码有效,它仅返回Boolean, True
或False
。 And do not assign any values. 并且不要分配任何值。
If you need to assign value, use a single =
such as 如果需要分配值,请使用单个=
例如
complete_y = y2 - y1
You can't do 你做不到
float(x)=0.0
You're calling a function float
on a value x
and trying to assign 0.0
to the result of that call, which Python doesn't understand. 您正在调用值x
上的float
函数,并尝试将0.0
分配给该调用的结果,而Python无法理解。 Python knows the type of 0.0
, you don't have to specify that it's a float. Python知道0.0
的类型,您不必指定它是浮点数。 Just do 做就是了
x = 0.0
Also, I'm not sure what you expect your #calculate
section to do, but at the moment it won't have any effect on the rest of the program in any way. 另外,我不确定您希望#calculate
部分会做什么,但是目前它不会以任何方式对程序的其余部分产生任何影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.