2014-11-25 69 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