私はそれを呼び出すたびに関数からの戻り値のすべてを格納する方法はありますか?関数内で新しい変数を自動的に生成するにはどうすればよいですか?
def workdaystart(dayoftheweek):
starthour=input("What is your START HOUR for "+ dayoftheweek+"? ")
print("Is that AM or PM")#Allows us to differentiate between time periods#
print ("1. AM")
print ("2. PM")
print("3.I DONT WORK")
starthoursuffix = int(input('Enter your choice [1-2] : '))
if starthoursuffix == 1:
starthour=starthour+"AM"
elif starthoursuffix==2:
starthour=starthour+"PM"
else:
starthour=" "
return starthour
daysofweek=
["monday","tuesday","wednesday","thursday","friday","saturday","sunday"]
for day in daysofweek:
x=workdaystart(day)
あなたはそれが機能して、リスト内の項目を実行しますが、私はその日の開始時間は、目的球の外で変数として格納したい見ることができるように:ここではコードです。
これは 'x = workdaystart(day)'のように、開始時刻を変数 'x'に格納します。 – Barmar
しかし、それはオーバーライドされ続けるでしょう。ループの後、 'x'の値は日曜日の値になります。日付をキーに、開始時間を値として辞書を作成する – ton