# how to check if a number is even in python

25 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?

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
31 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.
8 views
I need to check if a number is a perfect squre in java.
16 views
1 vote
43 views
Problem: I was trying to check if an element does exist in a list using a pyhton program: primary_list = [ 10, 12, 16, 6, 20, 33 ] a = input("Please enter a number to check if this exists in the list: ") print("Checking if input exists in this list : ") for ... not giving any output that is right. What should I do to fix this and how to check if an element does exist in a list. Thanks in advance.
1 vote
22 views
Problem: I tried to check if a string is a palindrome or not so I wrote this program in python: def Word(str): for i in range(0, len(str)/2): if str[i] != str[len(str)-i-1]: return False return True a = input("Enter a word to check:") ... TypeError: 'float' object cannot be interpreted as an integer What should I do now and how to check if a string is a palindrome or not using python program?
19 views
Problem: Hi all, I am trying to figure out the dictionary related problems in python. Dictionary is really fun to learn and work with. Let&rsquo;s say, I have a dictionary dict = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'} If ... needed to check every value inside the dictionary what can I do for that? So, I want to know how to check if a value is in a dictionary python?
22 views
I am new to python programming I was trying to check if a letter is uppercase in python. I wrote some code to check this statement : import string def UpperCase(s_str): for x in s_str: if x not in string.UpeerCase: return False return True But I can not get the actual ... last): File "<stdin>", line 1, in <module> NameError: name 'LoWWE' is not defined Can anyone help me to solve this thing?