Contents
- function_example.py
- module_example.py
function_example.py 1/2
[top][prev][next]
# Examples using built-in functions
# Sara Sprenkle
x = 3.14159
print "We start with x having value", x
roundx = round(x)
print "We round x to the nearest int", roundx
roundx = round(x,1)
print "We round x to the nearest tenth", roundx
roundx = round(x,3)
print "We round x to the nearest thousandth", roundx
print
print "x is of", type(x)
module_example.py 2/2
[top][prev][next]
# Example of importing a module
# by Sara Sprenkle
#
import math
i = 1j
# The equation e^(i pi) + 1 = 0
shouldbezero = math.e ** (i * math.pi) + 1
print "e^(i pi) + 1 equals", shouldbezero
# practice using functions from modules
print "100^(1/2) =", math.sqrt(100)
Generated by GNU enscript 1.6.4.