- 3

Leap year

Given the year number. You need to check if this year is a leap year. If it is, print LEAP, otherwise print COMMON. The rules in Gregorian calendar are as follows: a year is a leap year if its number is exactly divisible by 4 and is not exactly divisible by 100 a year is always a leap year if its number is exactly divisible by 400 Warning. The words LEAP and COMMON should be printed all caps. thats my code please can someone explain why it doesn't work properly? here is where you can check my code: https://snakify.org/en/lessons/if_then_else_conditions/problems/leap_year/ a = int(input()) if abs(a % 4 == 0) or a 4 ==0: print("LEAP") elif abs(a / 400): print("COMMON")

1st Feb 2021, 11:54 PM
Ailana
Ailana - avatar
5 ответов
0
#In 2nd line of code 'and' will be used not or and the code will be a = int(input()) if abs(a % 4 == 0) and a%100 != 0: print("LEAP") elif abs(a / 400): print("COMMON") #Just copy and paste it in Sololearn Codes playground and see it's work
2nd Feb 2021, 12:18 AM
Abhay
Abhay - avatar
0
a%4==0 and not a%100==0 or a%400==0: leap Else: Common
2nd Feb 2021, 12:30 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
def is_leap_year(year): """Check whether a year is a leap year. A leap year is divisible by 4 but not if divisible by 100 unless also divisible by 400. """ return not year % 400 or not year % 4 and year % 100
2nd Feb 2021, 3:53 AM
David Ashton
David Ashton - avatar
0
year = int(input()) if abs(year % 4 == 0) and abs(year % 100 != 0): print("Leap year") elif abs(year // 400 ): print("Not a leap year") """ cant find whats wrong but here "'"
1st Apr 2021, 2:05 PM
CancersGr.t
CancersGr.t - avatar
0
CancersGr.t 1) output should be LEAP / COMMON. 2) your categories are reversed 3) control flow is wrong. Either reverse order (check 400 first etc). Or combine conditions with "and" like in the description 4) also for 400 you have to use modulo Additionally you don't need abs()
1st Apr 2021, 2:24 PM
Benjamin Jürgens
Benjamin Jürgens - avatar