我试图让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