- 2
Leap year project.
How to write leap year project in python??
7 Antworten
+ 4
You need examples and inspirations?
Code Playground is a good place to begin the search 👍
+ 3
First try to solve the task yourself. Show what your problems are. Otherwise a ready-made solution is googled in a couple of seconds.
+ 3
Take a look at these guides on how to ask a question.
https://stackoverflow.com/help/how-to-ask
https://www.sololearn.com/blog/38/8-simple-rules-to-get-help-from-the-community
+ 3
It's already good try. You just forgot to complete the if-else constructions
if year%4 == 0:
if year%100 == 0:
if year%400 == 0:
print("leap year")
else: #something here
else: #something there
else: print("not a leap year")
Ps. for sure you can combine ALL conditions in long one
+ 1
khizar First, correct the indentation. Python identifies blocks by their indentation, so having it wrong breaks everything. Read the lessons on blocks or if statements.
Second, correct variables and commands casing. if, then, else, print, and almost every command or function is lower case. Also, you assign a value to variable "Year", but then call variable "year".
Finally, the code doesn't output when year is multiple of 4 but not leap. My advice: use a single "if" statement and combine conditions with boolean operators.
0
Year = int(input())
If year % 4 == 0:
If year % 100 != 0:
If year % 40p == 0:
Print ("leap year")
Else:
Print ("not a leap year")
0
But this code doesn't work