473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Sep 4 '10 #1
3 6234
dwblas
626 Expert 512MB
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
bvdet
2,851 Expert Mod 2GB
Learn about the % (modulo) operator here. Example:
Expand|Select|Wrap|Line Numbers
  1. >>> var = 67
  2. >>> not var%2
  3. False
  4. >>> var = 66
  5. >>> not var%2
  6. True
  7. >>> 
Sep 5 '10 #3
Thekid
145 100+
What about something like this:

Expand|Select|Wrap|Line Numbers
  1. n = raw_input('give a number: ')
  2. x=(int(n))
  3. if x%2==0:
  4.    print '%i is divisible by 2' % (x)
  5. else:
  6.    print '%i is not divisible by 2' % (x)
  7.  
Sep 10 '10 #4

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

Similar topics

7
by: Jack | last post by:
Hi, I have the following piece of code:If RS.EOF or RS.BOF Then Session("Authenticated") = False Response.Write "Sorry, your userid or password did not match" Response.Write "<BR>"...
8
by: Jack | last post by:
Hi, Here is my problem: I am logging in to a page, where the page retrieves a record from a database. The text boxes are used in the display formto let the users update the fields, if they...
2
by: Jack | last post by:
Hi, I need to write a reponse.write statement of the following: <A HREF="default.htm">Click Here to try again</A> However, I am not clear about the syntax to handle this. I appreciate any help....
2
by: John | last post by:
Hi, I am getting syntax errors in my JavaScript code, code snippet as follows (between my <script></script> tags: document.write(<a title="Nice to meet you" href="http://www.mydomain.com/"...
4
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
5
by: CBKowitz | last post by:
I have a page that calls a public sub that is in the code behind page. This sub will, depending on the number of records, write out a number of statements. One of the statements that is repeated...
1
by: leopl | last post by:
Dear all I have written a write statement as follow:- write #1 me.textmessage the output came out to be as follow:- "(contents of the me.textmessage)"
5
by: rn5a | last post by:
A Web Form has a TextBox within a DataGrid wherein users are expected to enter only whole numbers. It should be validated so that the TextBox doesn't remain blank or any non-numeric data is...
4
by: ajmastrean | last post by:
I cannot get any (hex) number in the "0x80"-"0x89" range (inclusive) to write properly to a file. Any number in this range magically transforms itself into "0x3F". For instance, debugging shows...
28
by: Tony Johansson | last post by:
Hello! If I write this statement int number = new int(); I don't get compiler error or run time error but how will the compiler read such a statement ? For example will number be a reference...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.