class thing(): def thisthing(): def thatthing(): def printthing(): etc.
I was in the process of creating method that utilizes a "table" of possible values that they could fall into where such data would be gathered through input and the it outputs the star type in another method. When I set up the "asking" method, I gathered the data necessary and set it to display the star type method. The result? I consistently get a NameError like so: "NameError: global name 'star_type' is not defined". I'm not sure exactly why its behaving this way, maybe you guys will know a bit more.
pasting relevant code:
def constant():
global sun_mass
sun_mass = 1.9891*(10**30) #kilograms: kg
global sun_radi
sun_radi = 6.96242*(10**8) #meters: m
def star_type(mass,radius):
classification = ["O","B","A","F","G","K","M"]
if mass <= (0.45*sun_mass) and radius <= (0.70*sun_radi):
return classification[6]
elif (0.45*sun_mass) < mass < (0.80*sun_mass) and (0.70*sun_radi) < radius < (0.96*sun_radi):
return classification[5]
elif (0.80*sun_mass) < mass < (1.04*sun_mass) and (0.96*sun_radi) < radius < (1.15*sun_radi):
return classification[4]
elif (1.04*sun_mass) < mass < (1.40*sun_mass) and (1.15*sun_radi) < radius < (1.40*sun_radi):
return classification[3]
elif (1.40*sun_mass) < mass < (2.10*sun_mass) and (1.40*sun_radi) < radius < (1.80*sun_radi):
return classification[2]
elif (2.10*sun_mass) < mass < (16.0*sun_mass) and (1.80*sun_radi) < radius < (6.60*sun_radi):
return classification[1]
elif mass >= (16.0*sun_mass) and radius >= (6.60*sun_radi):
return classification[0]
else:
return "No such type exists/This star is extremely unusual"
def ask():
star_mass = 1.98*(10**30) #eval(raw_input("Mass of Star: "))
star_radi = 6.78*(10**8) #eval(raw_input("Radius of Star: "))
print star_type(star_mass,star_radi)
ask()
The output should be a "G" type star but it nameErrors, what do?
[edit:] Also note, all my other global constant values have no problem in being defined with some of the other functions/methods, but it's being a bit snotty with sun_mass/sun_radi with some of the varying attempts I've made since posting.

New Topic/Question
Reply




MultiQuote





|