- 2

Leap year solution

Can someone please explain how to do this practice question I’ve been stuck on it for so long and every time I use an elif it says invalid syntax. I’ve tried several solutions

8th Jul 2021, 9:53 AM
Eren Ozer
9 Réponses
+ 3
First of all, you have some indentation problems. Secondly, you have a problem with the condition. You should check it from 400 to 4(reverse style).Your code would be like this: https://code.sololearn.com/c542A19A4a2A
8th Jul 2021, 10:26 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
Can you show your attempt? If you don't know how to show then follow this: https://www.sololearn.com/post/75089/?ref=app
8th Jul 2021, 9:55 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
Because of the indentation, you get an error. You have written: if year % 4 != 0: print ("Not a Leap year") elif year % 100 != 0 : print("Not a Leap year") elif year % 400 == 0: print("Leap year") in the elif statement you have used chained identation. You should write like that: if year % 4 != 0: print ("Not a Leap year") elif year % 100 != 0 : print("Not a Leap year") elif year % 400 == 0: print("Leap year") As you can see there is not additional gap. You forget the remove the gap in the code which makes your code a chained statement and that's why you get the invalid syntax.
8th Jul 2021, 4:17 PM
The future is now thanks to science
The future is now thanks to science - avatar
0
year = int(input()) if year % 4 != 0: print ("Not a Leap year") elif year % 100 != 0 : print("Not a Leap year") elif year % 400 == 0: print("Leap year") Here is my most recent attempt. It keeps saying invalid syntax on the lines with elif
8th Jul 2021, 10:01 AM
Eren Ozer
8th Jul 2021, 10:01 AM
Eren Ozer
0
The future is now thanks to science[LESS ACTIVE] but whats the soul purpose behind the “ invaild syntax” for my elif statments
8th Jul 2021, 1:08 PM
Eren Ozer
0
#include <iostream> using namespace std; int main() { int a,b; int sum; cout << "Enter a number \n"; cin >> a; cout << "Enter another number \n"; cin >> b; sum = a+b; cout << "sum is: " << sum << endl; return 0; }
9th Jul 2021, 4:16 PM
Clovis Nginyu
Clovis Nginyu - avatar
0
Please what is wrong with that code, it doesn't run as requested
9th Jul 2021, 4:17 PM
Clovis Nginyu
Clovis Nginyu - avatar
0
@Clovis Nginyu Your code will work fine on any c++ compiler or ide.The problem is,in sololearn, you have to give input first in the box. So you have to give input: 5 6 or 5 6 after giving the input your code will work and then it will print. So it's better to use an IDE or compiler of c++. By the way, please ask your question in the Q&A discussion not in the answer of the other questions.Thank you.
10th Jul 2021, 7:43 AM
The future is now thanks to science
The future is now thanks to science - avatar