2014-11-25 34 views
0

我的问题其实很简单,也许问题在于我自己不知道python与Linux的正确参数。在python中运行需要输入的.py文件

我运行该文件使用输入从运营商既要运行的程序,并且还得到信息进行转换,这一点我将在下面的地方:当我在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 >>> ")); 

问题为“蟒蛇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

哪个Python版本使用的是? – 2014-11-25 06:36:09

+0

我可以在哪里看到'GalaxyConverter.py'的代码?它的文件? – Nilesh 2014-11-25 06:36:42

+0

添加更多代码。我们需要看到“GalaxyConverter.py” – Wedava 2014-11-25 06:37:32

回答

0

在Python 3,你可以在你的榜样使用input,它可以输入字符串。 但是在Python 2中,相同的功能是raw_input

input Python 2中的函数等于eval(raw_input(prompt)),它将计算输入字符串为Python表达式。

显然你的运行python版本是python 2,但我不知道代码的python版本是什么。但是,你需要修改所有inputraw_input如果是Python版本是2

编号:

https://docs.python.org/2/library/functions.html#input

https://docs.python.org/3/library/functions.html#input

相关问题