Python Forum
Trying to print corresponding elements in two different list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to print corresponding elements in two different list
#1
very new to python and it is also my first programming langue. i have two list one to take in user input for how much rainfall happened each month and the other for the months of the year. i want to output: each month with how much rainfall it had, the total rainfall for the year, the avg rainfall each month, and i want to add the max and min rainfall months. i now how to use max and min command built in and can get it to print but i don't know how to get the associated month to print with it. any help would be amazing.

for clarification: if march was the heaviest rainfall month of the year and it had 10 inches i would like the output to say "March had the highest rainfall of the year with 10 inches"

rainfall = []

months = ['January', 'February', 'March', 'April', 'May', 
         'June','July', 'August', 'September', 'October', 'November', 'December']

rainfall_year = 0

for x in months:
    day_rainfall = float(input(f" In {x} what was the rainfall for the month? "))

    rainfall.append(day_rainfall)

    rainfall_year += day_rainfall

    monthly_rainfall_avg = rainfall_year/12

for x in range(len(months)):
    print(f'{months[x]}: {rainfall[x]}')


print(f'Your total rainfall for the year is {rainfall_year}')
print(F'The monthly average rainfall for the year is: {monthly_rainfall_avg}')
Reply


Messages In This Thread
Trying to print corresponding elements in two different list - by Darthmarvolo - Mar-03-2020, 12:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to remove all elements from list based on a condition sg_python 3 468 Jan-27-2024, 04:03 PM
Last Post: deanhystad
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 496 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  How do you get Python to print just one value in a list? 357mag 3 1,034 May-17-2023, 09:52 PM
Last Post: rob101
  Checking if a string contains all or any elements of a list k1llcod3 1 1,119 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  How to change the datatype of list elements? mHosseinDS86 9 2,013 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,172 May-17-2022, 11:38 AM
Last Post: Larz60+
  Print List to Terminal DaveG 2 1,442 Apr-02-2022, 11:25 AM
Last Post: perfringo
  Why am I getting list elements < 0 ? Mark17 8 3,172 Aug-26-2021, 09:31 AM
Last Post: naughtyCat
  Looping through nested elements and updating the original list Alex_James 3 2,147 Aug-19-2021, 12:05 PM
Last Post: Alex_James
  Extracting Elements From A Website List knight2000 2 2,289 Jul-20-2021, 10:38 AM
Last Post: knight2000

Forum Jump:

User Panel Messages

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