• Register
0 votes
23 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?

10 7 2
6,050 points

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.

11 6 4
34,930 points

Related questions

1 vote
1 answer 28 views
28 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.
asked May 13 samhaz 5k points
0 votes
1 answer 2 views
2 views
I need to check if a number is a perfect squre in java.
asked Oct 5 Daniel Anderson 4k points
1 vote
1 answer 26 views
26 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.
asked May 16 samhaz 5k points
1 vote
1 answer 20 views
20 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?
asked May 15 samhaz 5k points
3 votes
1 answer 12 views
12 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’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?
asked Mar 24 Gavin 15.3k points