Python Forum
Help With Parallel Arrays
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help With Parallel Arrays
#1
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:
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)
Reply


Messages In This Thread
Help With Parallel Arrays - by toxicxarrow - May-02-2018, 07:20 AM
RE: Help With Parallel Arrays - by buran - May-02-2018, 07:49 AM
RE: Help With Parallel Arrays - by toxicxarrow - May-02-2018, 08:01 AM
RE: Help With Parallel Arrays - by ThiefOfTime - May-02-2018, 08:01 AM
RE: Help With Parallel Arrays - by killerrex - May-02-2018, 08:13 AM
RE: Help With Parallel Arrays - by toxicxarrow - May-02-2018, 08:15 AM
RE: Help With Parallel Arrays - by buran - May-02-2018, 11:03 AM
RE: Help With Parallel Arrays - by toxicxarrow - May-02-2018, 10:06 PM
RE: Help With Parallel Arrays - by snippsat - May-02-2018, 11:42 PM
RE: Help With Parallel Arrays - by toxicxarrow - May-03-2018, 11:47 PM
RE: Help With Parallel Arrays - by snippsat - May-04-2018, 02:54 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020