0
Python for beginner 21.1
year = int(input()) #your code goes here b = year % 4 c = year % 100 d = year % 400 if c == d: print("Leap year") elif b == c: print("Not a leap year") elif b == 0: print("Leap year") elif c == 0: print("Not a leap year") elif d == 0: print("Leap year") else: print("Not a leap year") Every case is solved except case 5 i will post the rest you need in the comments. Just a hint no complet solution pls
5 Antworten
+ 4
You need to remove the first if (c==d)statement and make d==0 as first condition
+ 1
Simba , instead of providing ready code, pls prefer to point out errors and give conceptual hints on the way to solve.
By solving the code themselves from our hints, the posters learn for real.
0
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 a 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.
0
Thats the lesson i have to solve
0
Pls link your code from code playground using + button inside your question. This allows us to test, what always helps us to help you.
That said, these comparisons doesn't make sense. For example: why year % 400 == year % 100 makes it a leap year?
My hint: do the comparisons in the same order as the checks you listed in your answer.