我的问题实际上是一个简单的问题,也许问题是我自己不知道Linux的python的正确参数。
我正在运行的文件使用来自运营商的输入来运行程序,并且还要获取要转换的信息,我将在下面添加:
Initial_LonH = float(input("\nEnter RA's Hour >>> "));
Initial_LonM = float(input("\nEnter RA's Minute >>> "));
Initial_LonS = float(input("\nEnter Ra's Second >>> "));
Initial_LatH = float(input("\nEnter Dec's Hour >>> "));
Initial_LatM = float(input("\nEnter Dec's Minute >>> "));
Initial_LatS = float(input("\nEnter Dec's Second >>> "));
我在python中运行此问题时出现" python GalaxyConverter.py,出现以下错误:
Traceback (most recent call last):
File "GalaxyConverter.py", line 105, in <module>
input_Runner = str(input("\nDo you wish to convert Right Ascension and Declination into Cartesian?"
File "<string>", line 1, in <module>
NameError: name 'yes' is not defined
似乎问题是文件不知道把我放入终端的命令作为python文件的输入。请问我应该怎么做才能解决这个问题?
整个代码如下:
from math import radians, sin, cos, sqrt, asin, atan
Minute_Con = 60;
Second_Con = 3600;
DT_Radians = 0.0174539252;
RT_Degrees = 57.29577951;
Radi_Verse = 879829141200000000000000;
WRunner = True
def HMS_Expand_Lon(LongitudeH, LongitudeM, LongitudeS):
##{
print("\n The Right Ascension starts as " + str(LongitudeH) + ":" + str(LongitudeM) + "." + str(LongitudeS));
LongitudeM = LongitudeM/Minute_Con;
LongitudeS = LongitudeS/Second_Con;
LongitudeHMS = LongitudeH + LongitudeM + LongitudeS;
LongitudeHMS = LongitudeHMS * 15;
print("\n The Right Ascension becomes " + str(LongitudeHMS));
return LongitudeHMS
##}
def HMS_Expand_Lat(LatitudeH, LatitudeM, LatitudeS):
##{
print("\n The Declination starts as " + str(LatitudeH) + ":" + str(LatitudeM) + "." + str(LatitudeS));
LatitudeM = LatitudeM/Minute_Con;
LatitudeS = LatitudeS/Second_Con;
LatitudeHMS = LatitudeH + LatitudeM + LatitudeS;
LatitudeHMS = LatitudeHMS * 15;
print("\n The Declination becomes " + str(LatitudeHMS));
return LatitudeHMS
##}
def HMS_Convert_Lon(LongitudeHMS):
##{
LongitudeRAD = LongitudeHMS * DT_Radians;
print("\n The Right Ascension becomes " + str(LongitudeRAD));
return LongitudeRAD
##}
def HMS_Convert_Lat(LatitudeHMS):
##{
LatitudeRAD = LatitudeHMS * DT_Radians;
print("\n The Declination becomes " + str(LatitudeRAD));
return LatitudeRAD
##}
def RAD_Convert_Lon(LongitudeRAD, LatitudeRAD):
##{
Con_Lon = LongitudeRAD * LongitudeRAD;
Con_Lat = LatitudeRAD * LatitudeRAD;
Con_Lat_Lon = sqrt(Con_Lat + Con_Lon);
print("\n The Right Ascension becomes " + str(Con_Lat_Lon));
return Con_Lat_Lon
##}
def RAD_Convert_Lat(LongitudeRAD, LatitudeRAD):
##{
Con_Lon = LongitudeRAD;
Con_Lat = LatitudeRAD;
Con_Lon_Lat = atan(Con_Lon / Con_Lat);
print("\n The Declination becomes " + str(Con_Lon_Lat));
return Con_Lon_Lat
##}
def POL_Convert_Lon(LongitudePOL, LatitudePOL):
##{
POL_Lon = LongitudePOL * cos(LatitudePOL);
DEG_Lon = POL_Lon * RT_Degrees;
print("\n X finally becomes " + str(DEG_Lon));
return DEG_Lon
##}
def POL_Convert_Lat(LongitudePOL, LatitudePOL):
##{
POL_Lat = LongitudePOL * sin(LatitudePOL);
DEG_Lat = POL_Lat * RT_Degrees;
print("\n Y finally becomes " + str(DEG_Lat));
return DEG_Lat
##}
def main():
##{
Initial_LonH = float(input("\nEnter RA's Hour >>> "));
Initial_LonM = float(input("\nEnter RA's Minute >>> "));
Initial_LonS = float(input("\nEnter Ra's Second >>> "));
Initial_LatH = float(input("\nEnter Dec's Hour >>> "));
Initial_LatM = float(input("\nEnter Dec's Minute >>> "));
Initial_LatS = float(input("\nEnter Dec's Second >>> "));
Lon_Expanded = HMS_Expand_Lon(Initial_LonH, Initial_LonM, Initial_LonS);
Lat_Expanded = HMS_Expand_Lat(Initial_LatH, Initial_LatM, Initial_LatS);
Lon_Converted = HMS_Convert_Lon(Lon_Expanded);
Lat_Converted = HMS_Convert_Lat(Lat_Expanded);
Lon_RAD = RAD_Convert_Lon(Lon_Converted, Lat_Converted);
Lat_RAD = RAD_Convert_Lat(Lon_Converted, Lat_Converted);
Lon_POL = POL_Convert_Lon(Lon_RAD, Lat_RAD);
Lat_POL = POL_Convert_Lat(Lon_RAD, Lat_RAD);
X_Scaled = Lon_POL / Radi_Verse;
Y_Scaled = Lat_POL / Radi_Verse;
print("\n To scale of the theoretical length of universe, X = " + str(X_Scaled));
print("\n To scale of the theoretical length of the universe, Y = " + str(Y_Scaled));
##}
while WRunner == True:
input_Runner = input("\nDo you wish to convert Right Ascension and Declination into Cartesian?"
"\nif so, please type yes, if not, please type no >>> ");
if input_Runner == "yes":
main();
if input_Runner != "yes":
break
答案 0 :(得分:0)
在python 3中,您可以在示例中使用input
,它可以输入字符串。
但是在python 2中,相同的函数是raw_input
。
input
函数等于eval(raw_input(prompt))
,它将输入字符串作为Python表达式进行评估。
显然你运行的python版本是python 2,但我不知道代码的python版本是什么。但如果python版本为2,则需要将所有input
修改为raw_input
。
价: