#๐ Stuck with python exercise
24 messages ยท Page 1 of 1 (latest)
@ocean lynx
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.
sorry both pics don't make sense. 1 is about leap year, the other is about soup?
hey thanks for pointing it out. just fixed it!
you're not checking any years beyond the initial input
So would I have equate my year input to lyear and syear in the while true sections?
try increasing the year from the input onwards and for each year check if the year is leap or not
Okay will give it a shot!
oof
ik a faster way
year = int(input("Year: "))
expected = year + 4 - (year % 4)
if expected % 100 == 0:
print(f"The next leap year is: {expected + 4}")
else:
print(f"The next leap year is: {expected}")
after you get a year
you will get the remainder of that year with 4
then take 4 subtract with that remainder and add that value to the current year value
because, if your year has remainder of n, you need 4 - n years to get to the next leap year (n > 0)
and in case the current year is a leap year, you just need to add 4 (4 - 0) to the current year
so the formula is current year + (4 - remainder of current year to 4)
break the brackets and you get current year + 4 - remainder of current year to 4
this works 100% im sure about that
if the result is divisible by 100, just add 4 more
@ocean lynx hope you understand this fast solution (only requires math and some conditions)
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.