¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita+ 4
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")
10 Respuestas
+ 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😅
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
This post comprehensively covers the various aspects of Geometry Dash, highlighting its features, game modes, and customization options. It emphasizes the benefits of downloading the APK directly from the website and provides useful tips to maximize enjoyment and performance in the game. i.e: https://www.thegeometrydashapk.com/en/geometry-dash-android/
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
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");
}
}
}