Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm a beginner to python. So want to know the problem here.

What I have tried:

Python
print('type a number:')
number=int(input("Enter a number"))
if (number % 2)!=0 :
return "Weird"
elif :
(2<=n=>5)
print("Not Weird")

elif :
(6<=n=>20)
print("Weird")

elif:
(n>20)
print("Not Weird")
Posted
Updated 26-Jul-18 1:37am
v2

That can't be actually answered because your posted code has no indentation at all while Python requires proper indentation.

But your elif statements are wrong. Their syntax is similar to those of if statements (see 4. More Control Flow Tools — Python 2.7.15 documentation[^] ):
Python
if [expression]:
    # code to be executed when condition is true goes here
elif [expression]:
    # code to be executed when condition is true goes here
# End of if - elif here
 
Share this answer
 
Comments
CPallini 26-Jul-18 7:35am    
Indeed. My5.
It should be:
Python
print('type a number:')
n = int(input("Enter a number: "))
if (n % 2) !=0 :
  print("Weird")
elif (n>= 2 and n<=5):
  print("Not Weird")
elif (n>= 6 and n<=20):
  print("Weird")
elif (n>20):
  print("Not Weird")
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900