Is there a way to use an if statement depending on whether class variables exist? For example I have a menu and the first option is to set the variables, and the second is to display those. At the moment, if you try to display the variables before you have set them, the program crashes.
I tried to put
if class Gen0() == True:
and then have the rest of the code, but it didn't work. Or, should this be on a while loop so that the menu will pop up again? Currently if you select an incorrect answer, the program will tell you this, and print the menu again
elif ans == "2":
class Display(Gen0):
# Generation 0 values are produced #
# Currently the python error code will come up if you select this option before setting the values #
print("Generation 0 values, and other options")
print("")
print("Your juvenile generation 0 population is ", Gen0.juvenile_population)
print("Your juvenile survival rate is ", Gen0.juvenile_survival)
print("Your adult generation 0 population is ", Gen0.adult_population)
print("Your adult survival rate is ", Gen0.adult_survival)
print("You senile generation 0 population is ", Gen0.senile_population)
print("Your senile survival rate is " , Gen0.senile_survival)
print("Your birth rate is " ,Gen0.birth_rate)
print("Your disease factor is ", Gen0.disease)
print("Disease will be triggered once the population reaches " ,Gen0.disease_trigger)
print("Your population model will go on for ",Gen0.generations , "generations")
Aucun commentaire:
Enregistrer un commentaire