Simple Numeric Computation

CS 233 Python Lecture Examples

#!/usr/bin/python
# Some calculations. Note the lack of semicolons. Statements end at the end
# of the line. Also, variables need not start with a special symbol as in
# perl and some other Unix-bred languages.
fred = 18
barney = FRED = 44; # Case sensistive.
bill = (fred + barney * FRED - 10)
alice = 10 + bill / 100 # Integer division truncates
frank = 10 + float(bill) / 100
print "Bill = ", bill
print "Alice = ", alice
print "Frank = ", frank
# Notice the implied newline at the end of prints.
# Python also allows for multiple assignments, like perl list assignments
# but w/o the parens.
x,y,z = 15, barney - fred, 99
print x, y, z
# Python allows lines to be continued by putting a backslash at the end of
# the first part.
fred = bill + alice + frank - \
x - y - z
print fred