如何从setGen()
返回多个值?
def menu():
option = int(input("Please select an option: \n 1: Set Generation 0 Values \n 2: View Generation 0 Values \n 3: Run Model"))
if option == 1:
setGen()
elif option == 2:
displayGen()
elif option == 3:
runModel(juveniles,adults,seniles)#,jSrate,aSrate,sSRate,bRate,endGeneration)
elif option == 4:
print(adults)
menu()
def setGen():
#enter number of juveniles
juveniles = int(input("How many juveniles are in the total popluation?"))
#enter number of adults
adults = int(input("How many Adults are in the total popluation?"))
#enter number of seniles
seniles = int(input("How many Seniles are in the total popluation?"))
#enter juvenilesenile survival rates
return(juveniles,adults,seniles)
menu()
我无法想到在函数运行时再次运行菜单的方法,而且变量似乎不会返回到调用函数
答案 0 :(得分:0)
在选项1中,您正在调用setGen()
,但您没有将该函数的返回值分配给变量,因此您正在丢失数据。尝试将该行更改为
juveniles,adults,seniles = setGen()