Determine if a number is divisble by 2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abc123wfh
    New Member
    • Sep 2010
    • 1

    Determine if a number is divisble by 2

    How do i write an if statement that determines if a number is divisble by 2? Please help
    Last edited by bvdet; Sep 5 '10, 02:38 PM. Reason: Edit thread title, ask the question in the message
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    If you don't pay attention in class it's going to be a long, long semester. http://lmgtfy.org/?q=python+%22even+number%22

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      Learn about the % (modulo) operator here. Example:
      Code:
      >>> var = 67
      >>> not var%2
      False
      >>> var = 66
      >>> not var%2
      True
      >>>

      Comment

      • Thekid
        New Member
        • Feb 2007
        • 145

        #4
        What about something like this:

        Code:
        n = raw_input('give a number: ')
        x=(int(n))
        if x%2==0:
           print '%i is divisible by 2' % (x)
        else:
           print '%i is not divisible by 2' % (x)

        Comment

        Working...