+ 2
Kindly check discription for question
You need to make a program to take a year as input and output "Leap year" if itโs a leap year, and "Not a leap year", if itโs not. To check whether a year is a leap year or not, you need to check the following: 1) If the year is evenly divisible by 4, go to step 2. Otherwise, the year is NOT leap year. 2) If the year is evenly divisible by 100, go to step 3. Otherwise, the year is a leap year. 3) If the year is evenly divisible by 400, the year is a leap year. Otherwise, it is not a leap year. Sample Input 2000 Sample Output Leap year Use the modulo operator % to check if the year is evenly divisible by a number.
32 Answers
+ 7
you can write it by yourself: I've give you enough hints to do so ;P
year divisible by n: year % n == 0
year NOT divisible by n: year % n != 0
+ 2
show your code, so we can tell you what's wrong and how to fix it ;P
numbers divisible by d have remainder of number / d equals to zero...
+ 1
Vkd not putting != or == is valid, as value wich are not 0 or not empty structures are evaluated to true (false otherwise)
0
where is your attempt?
try first by yourself, and if you stuck, we could help you to complete by yourself... but we must see your code ^^
0
Bro I am having a issue
0
How Python will recognise
0
Is there any remainder
0
I tried. but I don't know to make python to check it that there is any remainder or not
0
:I.
0
visph I first try by myself then only post doubts ๐
0
post what you have tried so far...
operator to get remainder is %
0
visph I know how to get remainder but how to deal with it
0
visph my code was giving error invalid syntax
0
Ohkk. Got it what you mean. Thanks๐๐ ๐๐ป
0
year = int(input())
#your code goes here
x = year % 4
y = year % 100
z = year % 400
if x == 0:
if y == 0:
if z == 0:
print ("Leap Year")
else:
print ("Not a Leap Year")
0
Kindly tell whats the problem
0
you should put more than one space to clearly see your code blocks ;P
anyway, your logic is wrong:
if year divisible by 4
and if year divisible by 100
and if year divisible by 400
leap year
else (if not year divisible by 4)
not leap year
but leap year if year divisible by 4, except if year not divisible by 100 or divisible by 400: 2000 is leap year, 1900 is not leap year...
in other words:
if year divisible by 400 or (year divisible by 4 and NOT divisible by 100)
leap year
else
not leap year
0
Can you tell me how to write. I am still unable to get it. Iam trying my hard visph