Hello guys, can someone help me... I need to write a program that print the upcoming leap year depending on the year we entered... I was able to do 50% of the job... the issue comes when a year which isn't divisible by 400 comes it... a year which is divisible by 4 but not by 400 isn't considered to be a leap year... how should I proceed please
#๐ Program to find upcoming leap year
13 messages ยท Page 1 of 1 (latest)
@verbal wedge
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
In the picture, notice I got the year 1900 as a leap year but this is wrong because it isn't divisible by 400
a year which is divisible by 4 but not by 400 isn't considered to be a leap year
This isn't quite right
When determining if a century is a leap year, we have to divide by 400
so 1500 and 1700 are not leap years, but 1600 is
I really recommend not trying to do it in 1 massive if. Use nested statements to make it simpler to work with
^ either use multiple if statements, or, break it apart onto new lines
if year % 4 == 0:
...
else:
print("Not leap year!")
using one major if/else to separate the years like this already narrows things down immensely
now you just need a little bit of extra logic in the year % 4 == 0 block
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.