#๐Ÿ”’ Stuck with python exercise

24 messages ยท Page 1 of 1 (latest)

ocean lynx
#

Hey guys I've been stuck on this exercise for a while now could someone please help/guide me on how to solve this?

open jasperBOT
#

@ocean lynx

Python help channel opened

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.

elder sonnet
ocean lynx
ocean lynx
prisma locust
#

you're not checking any years beyond the initial input

ocean lynx
#

So would I have equate my year input to lyear and syear in the while true sections?

prisma locust
ocean lynx
#

Okay will give it a shot!

river snow
#

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)

open jasperBOT
#
Python help channel closed

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.