• Register
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?

10 7 2
6,060 points

Please log in or register to answer this question.

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,950 points

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.
asked May 13, 2020 samhaz 5k points
0 votes
1 answer 6 views
6 views
Problem: Is there anyone to helo on > 'how to check if a number is even' ?
asked Mar 17 sadi1982 36.3k points
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?
asked Dec 21, 2020 ZarinaShaik 320 points
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
asked Mar 25 MUHAMMAD MUNEEB 82.5k points
0 votes
1 answer 2 views
2 views
Problem : Please help me on > 'check if number is even or odd java' ?
asked Mar 17 sadi1982 36.3k points
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
asked Mar 31 MUHAMMAD MUNEEB 82.5k points
1 vote
1 answer 2 views
2 views
Problem: Can someone please help fix this uncaught error : python check if string is a number
asked Mar 30 MUHAMMAD MUNEEB 82.5k points
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!
asked Mar 8 Mashhoodch 13k points
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.
asked Mar 11, 2020 LizzyM 6.1k points
0 votes
1 answer 15 views
15 views
I need to check if a number is a perfect squre in java.
asked Oct 5, 2020 Daniel Anderson 4k points