Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping and nested loops
#1
all_days = ["Monday", Tuesday", "Wednesday", "Thursday","Friday", "Saturday", "Sunday")
total_rain = 0 
total_weeks = 0 

# number of weeks
while True:
    try:
        total_weeks = int(input("Enter number of weeks for which rainfall should be calculated "))
    except NameError:
        print("Number of weeks must be an interger")
    else:
        if total_weeks < 1:
            print("Number of weeks must be at least 1")
        else:
            break
## rain by days of the week 

for weeks in range(total_weeks):
    for days in all_days:
        print("enter the rain for:",(days(0)) + 1 ), "in" (range(total_weeks))
I've just started an into to programming course and its all online and finding it SO hard to get support for the uni, so if someone would be able to point me in the direction of what I'm trying to do!

I need to ask a user to tell me how many weeks they want to know the average rainfall for (which I've gotten to work)
the system then needs to ask them for everyday of the week, of all weeks requested how many mm of rain fall on that day and then add up the value of each day to find averages. I cannot for the life of me make the day and weeks loop through :(

Please assist Cry Cry Cry
Reply


Messages In This Thread
Looping and nested loops - by albry - Dec-20-2018, 10:52 AM
RE: Looping and nested loops - by buran - Dec-20-2018, 10:56 AM
RE: Looping and nested loops - by albry - Dec-20-2018, 11:16 AM
RE: Looping and nested loops - by buran - Dec-20-2018, 11:31 AM
RE: Looping and nested loops - by albry - Dec-20-2018, 12:02 PM
RE: Looping and nested loops - by buran - Dec-20-2018, 12:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  for loops break when I call the list I'm looping through Radical 4 912 Sep-18-2023, 07:52 AM
Last Post: buran
  reduce nested for-loops Phaze90 11 1,937 Mar-16-2023, 06:28 PM
Last Post: ndc85430
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 1,727 Aug-19-2022, 11:07 AM
Last Post: dm222
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,606 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  breaking out of nested loops Skaperen 3 1,241 Jul-18-2022, 12:59 AM
Last Post: Skaperen
  Break out of nested loops muzikman 11 3,401 Sep-18-2021, 12:59 PM
Last Post: muzikman
  Looping through nested elements and updating the original list Alex_James 3 2,147 Aug-19-2021, 12:05 PM
Last Post: Alex_James
  How to break out of nested loops pace 11 5,422 Mar-03-2021, 06:25 PM
Last Post: pace
  Nested for Loops sammay 1 8,843 Jan-09-2021, 06:48 PM
Last Post: deanhystad
  How to make this function general to create binary numbers? (many nested for loops) dospina 4 4,450 Jun-24-2020, 04:05 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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