May-02-2018, 07:20 AM
I have a homework assignment, nothing urgent, but any help would be appreciated.
The goal is to gather an amount of rainfall for every month in a year. The program has to use two parallel arrays, one for the months, and one for the the amount of rain. Then it has to sort the rain amount in ascending order. My problem is that I can't really think of how to keep both arrays sorted in the exact same way so that both lists stay parallel. My two main problems are: how can I make the "X" in the prompt display the month that I'm gathering for, and how can I link the monthList to the rainAmount list after sorting the rainAmount list? I'd rather not use functions as I'm not very comfortable using them just yet.
Here is my code so far:
The goal is to gather an amount of rainfall for every month in a year. The program has to use two parallel arrays, one for the months, and one for the the amount of rain. Then it has to sort the rain amount in ascending order. My problem is that I can't really think of how to keep both arrays sorted in the exact same way so that both lists stay parallel. My two main problems are: how can I make the "X" in the prompt display the month that I'm gathering for, and how can I link the monthList to the rainAmount list after sorting the rainAmount list? I'd rather not use functions as I'm not very comfortable using them just yet.
Here is my code so far:
monthList = [ 'January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ] # rainAmount = [] size = 12 # for i in range(size): amount = input('Enter amount of rain for X month: ') rainAmount.append(amount) # for i in range(0, len(rainAmount) - 1): for j in range(0, len(rainAmount) - 1 - i): if rainAmount[j] > rainAmount[j+1]: rainAmount[j], rainAmount[j+1] = rainAmount[j+1], rainAmount[j] # print(rainAmount)