我試圖讓lowRain函數打印出月份中數組中的最小數字。 例如,當我運行rainInput函數中的循環並輸入這些數字(4,3,10,10,10,10,10,10,8,23,10)時,它將通過lowRain函數。當我嘗試返回產生最低雨量的月份時,我得到「12月份的最低降雨量爲10英寸。」如何打印出在python中使用字符串數組的最小數字?
def main():
rainfall = rainInput()
low, lowMonth = lowRain(rainfall)
print("The lowest rainfall for " + str(low) + " was " + str(lowMonth) + " inches.")
def rainInput():
rainfall = ["January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
for month in range(len(rainfall)):
rainfall[month] = (int(input("Please enter the amount of rain for " + str(rainfall[month]) + " :")))
return rainfall
def lowRain(rainfall):
month = ['January','Febuary','March','April','May','June','July','August','September','October','November','December']
lowMonth = min(month)
print(lowMonth)
for m, n in enumerate(rainfall):
if lowMonth:
lowMonth = n
low = m
return month[low], lowMonth
main()
爲什麼不使用字典? – bigbounty
爲了充分利用Stackoverflowit對於【提出好問題】(http://stackoverflow.com/help/how-to-ask)很重要,它包括創建一個[Minimal,Complete,and Verifiable](http:/ /stackoverflow.com/help/mcve)示例。 –
什麼是降雨量?發佈'lowRain'呼叫的一些例子 – RomanPerekhrest