By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 439,932 Members | 1,944 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,932 IT Pros & Developers. It's quick & easy.

# Determine if a number is divisble by 2

 P: 1 How do i write an if statement that determines if a number is divisble by 2? Please help Sep 4 '10 #1
Share this Question
3 Replies

 Expert 100+ P: 621 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 Sep 5 '10 #2

 Expert Mod 2.5K+ P: 2,851 Learn about the % (modulo) operator here. Example: Expand|Select|Wrap|Line Numbers >>> var = 67 >>> not var%2 False >>> var = 66 >>> not var%2 True >>>  Sep 5 '10 #3

 100+ P: 145 What about something like this: Expand|Select|Wrap|Line Numbers 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)   Sep 10 '10 #4

### Post your reply

Sign in to post your reply or Sign up for a free account.