我总是犯同样的错误
这可能是一个简单的错误,我只是有一段时间没有编码了
#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")
导致错误
expected result is a heading in degrees.
我的猜测是,您需要在赋值之前声明类型,例如:
在python中,只有在运行时才知道类型,不能声明变量的类型
如果您这样做:
您将看到x是一个字符串,因为您用
input
方法分配了一个字符串。如果你需要一个浮点数,你需要转换它作为旁注
如果前面声明了
y1
、y2
和complete_y
,则此代码有效,它只返回布尔值True
或False
。不要赋值如果需要赋值,请使用单个
=
,例如你不能这么做
您正在对值
x
调用函数float
,并尝试将0.0
赋值给该调用的结果,而Python无法理解。Python知道0.0
的类型,您不必指定它是一个float。就这么做吧另外,我不确定您希望
#calculate
部分做什么,但目前它不会以任何方式对程序的其余部分产生任何影响相关问题 更多 >
编程相关推荐