Python Forum
Python - Analyzing for even intergers and multiples
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python - Analyzing for even intergers and multiples
#2
A way to test for whether a number is even or not, is to use the "%" operator.

is_even = int(input("Enter a number: "))
if is_even % 2 == 0:
    print("True")
else:
    print("False")
You still need a way to keep asking the user to input an even number, if in fact, they enter 0 (zero), an odd number, or any non-integer response. Then print out the result in the required format.

Also, watch you indentation, Python is verity strict about it.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Messages In This Thread
RE: Python - Analyzing for even intergers and multiples - by sparkz_alot - Sep-03-2017, 08:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Analyzing data seperated by commas Kappel 2 1,989 Aug-07-2019, 01:46 PM
Last Post: ThomasL
  multiples of 3, smaller than 100 sonxy 1 2,549 Mar-27-2018, 10:56 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020