Whether no. is even or odd. What's wrong in this code?, why it's showing an error? | Sololearn: Learn to code for FREE!
¡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")

1st Jul 2024, 7:02 AM
Ashi Sharma
Ashi Sharma - avatar
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).
1st Jul 2024, 10:18 AM
Ipang
+ 2
Remove brackets in the if statement :). num = int(input("enter your number: ")) if num % 2 == 0: print("even") else: print("odd")
1st Jul 2024, 8:15 AM
Matěj Jonáš
Matěj Jonáš - avatar
+ 1
Oh okayy😅
1st Jul 2024, 10:03 AM
Ashi Sharma
Ashi Sharma - avatar
+ 1
Ipang Yeah, you are right. There is a slight indentation that Python does not like :D
1st Jul 2024, 10:43 AM
Matěj Jonáš
Matěj Jonáš - avatar
0
Dw, I had a same problem, because i am used to Java lol
1st Jul 2024, 10:06 AM
Matěj Jonáš
Matěj Jonáš - avatar
0
Yeah I tried it even by removing parentheses but it is showing error.
1st Jul 2024, 10:10 AM
Ashi Sharma
Ashi Sharma - avatar
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/
1st Jul 2024, 10:22 AM
Zesis Mark
Zesis Mark - avatar
0
To hard
2nd Jul 2024, 1:56 PM
Mia Cowling
Mia Cowling - avatar
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 '''
2nd Jul 2024, 9:47 PM
CyberX And CorruptedTiger
CyberX And CorruptedTiger - avatar
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"); } } }
3rd Jul 2024, 6:38 AM
Aditi Chand
Aditi Chand - avatar