Python examples: Difference between revisions

From AstroEdWiki
Jump to navigation Jump to search
No edit summary
Line 8: Line 8:


  x=1
  x=1
and then simply
x


and you'll see
and you'll see
1
Type
x=1.01
and then after you type "x" you'll see
x
1.01
Clearly you have a real-time calculator in hand, so try something more exciting.
x=1.01
y=1.0001
x/y
and you'll see something like this
1.0098990100989902
Modify that with
z=x/y
z
and you'll see the same result.  But now try
int(z)
and you'll see


  1
  1

Revision as of 06:46, 7 February 2013

This page contains examples and links to programs used for our Research Methods - Programming with Python short course.

Very simple Python

Start a Python interactive session using the "python" command to get a >>> prompt.

Type

x=1

and then simply

x

and you'll see

1


Type

x=1.01

and then after you type "x" you'll see

x
1.01


Clearly you have a real-time calculator in hand, so try something more exciting.

x=1.01
y=1.0001
x/y

and you'll see something like this

1.0098990100989902

Modify that with

z=x/y
z

and you'll see the same result. But now try

int(z)

and you'll see

1