0

毎日の水分摂取量、食事、運動などの日記に似たものを作成しようとしています。メニューで事前に定義されている特定の入力をユーザーに求めるメニューをいくつか作成しました。そこから、すべての出力印刷データを収集してファイルに保存する必要があります。ファイルは毎日更新されます (ユーザーに同じ定義済みの入力を求めます。

コードはかなり長いですが、次のようになります。

health = open('healthy.txt','a+')

date = input('Date:   ')

#Loop Menu for Exercise info for that day.
loop=True
while (loop):
    print ()
    print ("----------------------------------")
    print ("1 = Yoga")
    print ("2 = Cardio")
    print ("3 = Walk")
    print ("4 = Dance")
    print ("5 = Rest/None")
    print ("D = Done")
    print ("----------------------------------")
    print ()  

    exer = input('Exercise:   ')

    if (exer =='1'):
        print("Yoga")
    elif (exer =='2'):
        print("Cardio")
    elif (exer =='3'):
        print ("Walk")
    elif (exer =='4'):
        print ("Dance")
    elif (exer == '5'):
        print ("Rest/None")
    elif (exer =='d' or exer =='D'):
        loop=False
    else:
        print ("Invalid Option")
#End Exercise Menu        


dur = input('Duration(in minutes):   ')

#Loop menu for the Food Intake for particular date. 
loop=True
while (loop):
    print ()
    print ("----------------------------------")
    print ("1 = Protein")
    print ("2 = Starch")
    print ("3 = Fruit")
    print ("4 = Vegetable")
    print ("D = Done")
    print ("----------------------------------")
    print ()  

    food = input('Food:  ')

    if (food =='1'):
        print("Protein")
    elif (food =='2'):
        print("Starch")
    elif (food =='3'):
        print ("Fruit")
    elif (food =='4'):
        print ("Vegetable")
    elif (food =='d' or food =='D'):
        loop=False
    else:
        print ("Invalid Option")


#End Food Menu

fluid = input('Fluid Intake Total:   ')
#for line in health:

#Final print of info to be written to file
#not sure if I need the next four lines
food_true = False
food_total = 0
exer_true = False
exer_total = 0

for char in exer:
    if (exer_true == "Yoga"):
       print ("Yoga", end=" ")
    if (exer_true == "Cardio"):
        print ("Cardio", end=" ")
    if (exer_true == "Walk"):
        print ("Walk", end= " ")
    if (exer_true == "Dance"):
        print ("Dance",end=" ")
    if (exer_true == "Rest/None"):
        print ("Rest/None",end=" ")        
    else:
        loop=False

while(loop):
    if (food_true == "Protein"): 
        print ("Protein", end=" ")
    if (food_true == "Starch"):
        print ("Starch", end=" ")
    if (food_true == "Fruit"):
        print ("Fruit", end= " ")
    if (food_true == "Vegetable"):
        print ("Vegetable",end=" ")
    else:
        loop=False

print ("{:>10}".format("Date:        "),date)
print ("{:>10}".format("Exercises:   "),exer_total)
print ("{:>10}".format("Duration:    "),dur)
print ("{:>10}".format("Foods:       "),food_total)
print ("{:>10}".format("Fluids:      "),fluid)
print("-"*60)

#Save/Write to file function will be here
#Save/Write to file function will be here
health.write(info)#word "info" is a place holder only for final code info
health.close()

次の情報のみを印刷できるようにしたい (これには情報をファイルに保存することは含まれません)。演習: 出力(該当する場合はすべて) ;期間:出力 ;食品:出力(該当する場合は 4 つすべて);流体: 出力

毎日、プログラムを実行し、上記のすべてについて毎日の情報を更新します。次に、ファイルに情報を書き込んで、毎日同じファイルに保存する必要があります (毎日新しいファイルにすることはできません。したがって、コードの開始時に次を使用する必要があります。これは必須です): health = open(' Healthy.txt','a+')

4

0 に答える 0