0

Help me ! How should I do this? (Py)

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.

28th Aug 2021, 7:57 AM
a_mir__ _
6 odpowiedzi
+ 4
What have you tried so far?
28th Aug 2021, 8:20 AM
David Ashton
David Ashton - avatar
+ 4
Sacar , YES, you are right, you should not have given a ready solution to the asker. giving ready-made codes does not really help to progress in learning and it does not develop the problem solving ability. from my point of view, i find that this exercise is misplaced in the "python tutorial for beginners", because to develop a logic for it needs more experience. ==>>> an other issue is, that your code is not giving the correct answer in any case. try to use 2004 which is a leap year for sure, but it will result in that is is NOT a leap year.
28th Aug 2021, 8:37 AM
Lothar
Lothar - avatar
+ 4
a_mir__ _ , to give you a help, you can use this structure of nested if conditionals: ... if year 4 x == 0: if year % 100 == 0: if year % 400 == 0: print('...') else: print('...') else: print('...') else: print('not a leap year')
28th Aug 2021, 9:03 AM
Lothar
Lothar - avatar
+ 2
year = int(input()) if year % 4 != 0: print("Not a leap year") else: if year % 100 == 0: if year % 400 == 0: print("Leap year") else: print("Not a leap year") else: print("Not a leap year") I shouldnt have given the direct answer but i think thats what you want ..good luck!
28th Aug 2021, 8:22 AM
Sacar
Sacar - avatar
+ 2
Delicate Cat your algorithm is backwards. a % b means a is NOT divisible evenly by b. You need: if not year % 400 or year % 100 and not year % 4 https://code.sololearn.com/cOgB9UfjI1vp
29th Aug 2021, 1:37 PM
David Ashton
David Ashton - avatar
0
Sacar don’t feel guilty about giving a direct answer. i think how you anawered it was perfect.
30th Aug 2021, 4:38 AM
you are smart. you are brave.
you are smart. you are brave. - avatar