Sep-10-2019, 08:38 PM
(This post was last modified: Sep-10-2019, 09:09 PM by YoungGrassHopper.)
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:
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