+ 6
Whether no. is even or odd. What's wrong in this code?, why it's showing an error?
# A program to check if a number entered by user is odd or even num = int(input("enter your number: ")) if (num % 2 == 0): print("even") else: print("odd")
15 Réponses
+ 4
you have indentation error in your code
# A program to check if a number entered by user is odd or even
num = int(input("enter your number: "))
if (num % 2 == 0):
print("even")
else:
print("odd")
+ 3
The lines where `if` and `else` was written was indented. Those lines should be at the same indentation level with the line where input() was invoked (first line of code).
+ 2
Remove brackets in the if statement :).
num = int(input("enter your number: "))
if num % 2 == 0:
print("even")
else:
print("odd")
+ 1
Oh okayy😅
+ 1
TRY THIS ONE ......
You may change the int numb from 5 to somethimg else it will work
int num = 5;
if (num % 2 == 0){
System.out.print("even");
}
else{
System.out.print("odd");
}
}
}
0
Dw, I had a same problem, because i am used to Java lol
0
Yeah I tried it even by removing parentheses but it is showing error.
0
To hard
0
'''
old
copy this reply into the code (remove code first) if it dont work then dont save changes.
# A program to check if a number entered by user is odd or even
num = int(input("enter your number: "))
if (num % 2 == 0):
print("even")
else:
print("odd")
new
'''
num = int(input("enter your number: "))
if num % 2 == 0:
print("even")
else:
print("odd")
'''
explanation
so basically, the code you written.
num = int(input("enter your number: "))
==> if (num % 2 == 0):
print("even")
==> else:
print("odd")
the arrows point to the indents.
updated code:
num = int(input("enter your number: "))
if num % 2 == 0:
print("even")
else:
print("odd")
oh and the parentheses I forgor about those
anyways copy this text and paste it into the code (remove the old one)
see if it works
'''
0
Aditi Chand that's java this is a python question idiot
0
There is an indentation error in the if-else section
0
The error in your code is due to incorrect indentation before the if statement. In Python, proper indentation is crucial. The if statement should align with the rest of the code at the same level. Here's the corrected code:
# A program to check if a number entered by user is odd or even
num = int(input("enter your number: "))
if (num % 2 == 0): # No indentation before if
print("even")
else:
print("odd")
In the corrected code, the if statement is aligned with the num assignment, and the else statement is aligned with the if.
One of my client's website had simiilar issue. https://alightmotionproapks.com/
0
The error in your code is due to incorrect indentation for the if statement. In Python, indentation is crucial as it defines the block of code that belongs to control structures like if, else, for, and while.
Here’s the corrected version of your code:
python
Copy code
# A program to check if a number entered by user is odd or even
num = int(input("Enter your number: "))
if (num % 2 == 0):
print("even")
else:
print("odd")
I have created a page named codingsol on Honista App. You can get that app here: https://www.honistaapks.com/ and get more solutions of your coding problems directly into inbox.