私は緑色の個体数を計算するプログラムを作成しました。私が苦労している課題は、いくつかの一連の変数をExcelにエクスポートすることです。私はgreenfliesの数学を試しましたが、スプレッドシートに入れる方法を理解できません。コードは次のとおりです。Excelスプレッドシートへの変数のエクスポート
import winsound
import time
winsound.PlaySound("SystemHand", winsound.SND_ALIAS) #startup
#menu
print("Greenfly population model")
time.sleep(1)
one=1
print("1: Set the generation 0 values")
time.sleep(1)
two=2
print("2: Display the generation 0 values")
time.sleep(1)
three=3
print("3: Run the model")
time.sleep(1)
four=4
print("4: Export the data")
time.sleep(1)
five=5
print("5: Quit")
time.sleep(1)
#base code
while True: #wont shut down till option 5 is entered
print("")
ans=int(input("Please enter the number of the choice you want "))
if ans == one:
while True:
generations=float(input("Enter the number of generations you want the model to run for (Must be in 5 and 25 inclusive) "))
if generations < 5 or generations > 25:
print("Between 5 and 25 please")
else:
break
while True:
adultsur = float(input("Choose adult survival rate between 0 and 1 "))
if adultsur < 0 or adultsur > 1:
print ("Between 1 and 0 please") #wont mess up the decimals
else:
break
while True:
juvensur=float(input("Choose juvenile survivle rate between 0 and 1 "))
if juvensur < 0 or juvensur > 1:
print ("Between 1 and 0 please")
else:
break
while True:
sensur=float(input("Choose senile survivle rate between 0 and 1 "))
if sensur < 0 or sensur > 1:
print ("Between 1 and 0 please")
else:
break
juv=int(input("Choose the amount of juveniles "))
adu=int(input("Choose the amount of adults ")) #had issue with floats here so left it as int(input())
sen=int(input("Choose the amount of seniles "))
birth=int(input("Enter the birthrate of the adults "))
if ans == two:
print("The new generation to model is ",generations) #no issues here
time.sleep(1)
print("The adult survivul rate is ",adultsur)
time.sleep(1)
print("The juvenile survivul rate is ",juvensur)
time.sleep(1)
print("The senile survivul rate is ",sensur)
time.sleep(1)
print("There are ",juv," juveniles")
time.sleep(1)
print("There are ",adu," juveniles")
time.sleep(1)
print("There are ",sen," juveniles")
time.sleep(1)
print("The birthrate of adults is ",birth)
if ans == three:
print("Running module.")
time.sleep(0.1)
print("Running module..")
time.sleep(0.1)
print("Running module...")
time.sleep(0.1)
counter = 0
print("GENERATION JUVENILES ADULTS SENILES")
while generations > counter:
print ("",int(counter)," ", int(juv)," ", int(adu)," ", int(sen))
int(sen)
int(adu)#gets rid off the neverending decimals and rounds it up
int(juv)
sen *= sensur #takes out the old seniles
adu *= adultsur #does the math in a much simpler way than basic maths
juv *= len
juvn = juv
juv = adu * birth
sen += adu
adu += juvn
counter= counter+1 #will only repeat how many times the code was set to run
if ans == four
print ("",int(counter)," ", int(juv)," ", int(adu)," ", int(sen))
int(sen)
int(adu)
int(juv)
sen *= sensur
adu *= adultsur
juv *= len
juvn = juv
juv = adu * birth
sen += adu
adu += juvn
counter= counter+1
if ans == five:
print("Understandable, have a great day")
winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
winsound.PlaySound("*", winsound.SND_ALIAS)
break
エクスポートするか、私に教えてください。おかげさまで
エクスポートされたファイルを '.xls'や' .xlsx'形式のような実際のExcelファイルにしたいのですか、 '.csv'(カンマ区切りの値)で十分ですか?後者は書き出しが簡単で、書式は含まれませんが、Excelに簡単にインポートできます。注:必要以上に多くのコードを表示します。問題を示すための最小限のコードを示してください。 –