# how to check if a number is even in python

0 votes
32 views

How can i check if a number is even in python?

I am  new to programming and I was doing some practice. I wrote a code to check if a number is even in python:

``````number = int(input("Please enter a number to check"))
if (number % ) == 1
print("the number is even")``````

but it gives me an error :

``````  File "main.py", line 2
if (number % ) == 1
^
SyntaxError: invalid syntax``````

can anyone help me out to sort out this problem?

## 1 Answer

0 votes

In your code you have some logic problems . You should correct them. U should use:

``if (number % 2) == 0``

And your code should be like:

``````number = int(input("Please enter a number to check"))
if (number % 2) == 0
print("{0} the number is even".format(number))``````

If you use this code you can get accurate result for mgetting even number.

## Related questions

1 vote
1 answer 49 views
49 views
Problem: I wrote a code to check if a number is even or odd in python. The program is in the snippet below: number = input("Please enter any number to check if it is even or odd: ") result = number % 2 if result == 0: print("The number ... 2 TypeError: not all arguments converted during string formatting Why this error message is appearing & what is the problem with my program? Thanks in advance.
0 votes
1 answer 6 views
6 views
Problem: Is there anyone to helo on > 'how to check if a number is even' ?
0 votes
1 answer 34 views
34 views
Hi friends! So I am new to Java and a beginner. I do not have basic knowledge on programming. Can anyone explain me how to check if a number is even or odd using Java?
1 vote
1 answer 3 views
3 views
Problem: Any ideas on what I need to do to fix this? javascript check if number is even
0 votes
1 answer 2 views
2 views
Problem : Please help me on > 'check if number is even or odd java' ?
1 vote
1 answer 2 views
2 views
Problem: Can anyone tell me the solution of this problem? python check if a string is a number
1 vote
1 answer 2 views
2 views
Problem: Can someone please help fix this uncaught error : python check if string is a number
0 votes
1 answer 10 views
10 views
Problem: how to I Solve this: check if a number is prime python HELP! I need help understanding this: check if a number is prime python Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
0 votes
1 answer 24 views
24 views
Can I represent a string as number in python or how can I check if there is any number in string of python function. Supose a function is: def My_num(x): try: float(x) return True except ValueError: return False my question is calling float in the main function is ok or not and I am not getting my expected result.
0 votes
1 answer 15 views
15 views
I need to check if a number is a perfect squre in java.