Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for loop stumbling block
#1
Hey guys
I am busy with a task that is teaching me on how to use for loops which I need a little help.
Basically I need to use a for loop + if statements and:

● Write a program to input a year and a number of years. 
● Then determine and display which of those years were or will be leap  years. 

 
What year do you want to start with? 1994 
How many years do you want to check? ​8   

1994 isn’t a leap year 
1995 isn’t a leap year 
1996 is a leap year 
1997 isn’t a leap year 
1998 isn’t a leap year 
1999 isn’t a leap year 
2000 is a leap year 
2001 isn’t a leap year

I feel like my code is very close, I get the leap years displayed but my if statement for displaying the normal years as in the example above does not want to work, I only manage to get the leap years displayed. I am n total noob so its likely a very silly and obvious mistake.

If you can help, please explain as if you are talking to a 6 year old as I have 5days of coding experience in total.


Here is my code:


start = int(input("Which year to start on? "))
amount = int(input("How many years to check? "))
total = start + amount + 1
for years in range (start, total):
    if years %4 == 0:
        print(years, " This is a leapyear.")
        if years %4 != 0:
            print(years, " This is not a leapyear.")
    
    
Thanks in advance for any assistance
Reply


Messages In This Thread
for loop stumbling block - by YoungGrassHopper - Sep-10-2019, 08:38 PM
RE: for loop stumbling block - by metulburr - Sep-10-2019, 09:06 PM
RE: for loop stumbling block - by YoungGrassHopper - Sep-10-2019, 09:15 PM
RE: for loop stumbling block - by perfringo - Sep-11-2019, 05:59 AM
RE: for loop stumbling block - by YoungGrassHopper - Sep-11-2019, 07:20 AM
RE: for loop stumbling block - by perfringo - Sep-11-2019, 08:08 AM
RE: for loop stumbling block - by YoungGrassHopper - Sep-11-2019, 01:29 PM
RE: for loop stumbling block - by perfringo - Sep-11-2019, 02:45 PM
RE: for loop stumbling block - by YoungGrassHopper - Sep-11-2019, 03:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Stop/continue While loop block Moris526 68 25,750 Mar-28-2021, 09:21 PM
Last Post: Larz60+
  while loop stumbling block YoungGrassHopper 5 3,315 Sep-09-2019, 08:36 PM
Last Post: YoungGrassHopper

Forum Jump:

User Panel Messages

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