CSC111 FindMax.py with If Statements

From dftwiki3
Revision as of 09:12, 10 February 2014 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- --~~~~ ---- <source lang="python"> # findMax.py # D. Thiebaut # longest of 3 strings # s1 = "a long string" s2 = "a short one" s3 = "a much longer string" l1 = l...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut (talk) 09:12, 10 February 2014 (EST)


--D. Thiebaut (talk) 09:12, 10 February 2014 (EST)


# findMax.py
# D. Thiebaut
# longest of 3 strings
#

s1 = "a long string"
s2 = "a short one"
s3 = "a much longer string"

l1 = len( s1 )
l2 = len( s2 )
l3 = len( s3 )

# find the max lmax of l1, l2, l3
# (we assume that we do not know about the max() function!)

lmax = 40 # temporary

b1 = " " * ( lmax - l1 )
b2 = " " * ( lmax - l2 )
b3 = " " * ( lmax - l3 )


print( "|%s%s|" % ( s1, b1 ) )
print( "|%s%s|" % ( s2, b2 ) )
print( "|%s%s|" % ( s3, b3 ) )