print "This is a simple test program"
BOOK="C++ Programming in easy steps"
NUM=200
RULE="*****************************"
print RULE
print BOOK
print RULE
print "NUM is:",NUM
print "Double NUM:",NUM*2
if not 'BOOK' in locals():
BOOK="C++ Programming in easy steps"
print BOOK,
if not 'AUTHOR' in locals():
AUTHOR="Mike McGrath"
print " by ",AUTHOR
if not 'BOOK' in locals():
BOOK=""
if 'BOOK' in locals():
BOOK="Linux in easy steps"
print BOOK," by ",AUTHOR
import platform
plat=platform.system()
print plat," system"
if plat=="Windows":
print "Performing Windows-only tasks"
else:
print "Performing Linux-only tasks"
def add(x,y):
return x+y
def triple(x):
return (add(x,add(x,x)))
print "9 + 3 = ",add(9,3)
print "9 x 3 = ",triple(9)
def SQUARE(n):
return n*n
def CUBE(n):
return n*n*n
num=5
print "Macro SQUARE:",SQUARE(num)
print "inline square:",SQUARE(num)
print "Macro CUBE:",CUBE(num)
print "inline CUBE:",CUBE(num)
def LINEOUT(str):
print str
def GLUEOUT(a,b):
print a," ",b
longer="They carried a net "
line="and their hearts "
LINEOUT("In a bowl to sea went wise men three")
LINEOUT("On a brilliant night in June")
GLUEOUT(longer,line)
LINEOUT("On fishing up the moon.")
DEBUG=0
if DEBUG == 1:
def ASSERT(expr):
print expr, "...", num
if expr != True:
print "Fails in file: "# There is no concept of line in python
print "at line"# There is no concept of line in python
else:
print "Succeeds"
elif DEBUG == 0:
def ASSERT(expr):
print "Number is ",num
num = 9
ASSERT(num < 10)
num = num + num
ASSERT(num < 10)