Difference between revisions of "CSC111 Homework 2 Solutions 2011"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- =Solution Programs= ==hw2b.py== <source lang="python"> # hw2b.py # 111a-bm Ashleigh King # 111a-an Sam Scharr (working in pair programming) # # This program pro...")
 
(hw2b.py)
Line 30: Line 30:
 
</source>
 
</source>
  
:or this version, also good:
+
<br />
 +
<br />
 +
or this version, also good:
 +
<br />
 +
<br />
  
 
<source lang="python">
 
<source lang="python">

Revision as of 12:36, 3 October 2011

--D. Thiebaut 13:36, 3 October 2011 (EDT)


Solution Programs

hw2b.py

# hw2b.py
# 111a-bm  Ashleigh King
# 111a-an  Sam Scharr   (working in pair programming)
#
# This program prompts the user for a number and displays
# a number of lines corresponding to that number.
#
# Example of user interaction:
# How many lines do you want printed? 3
# *
# *... **
# **...... -***
# 

def main():
    lines = input( "How many lines do you want printed? " )
    lines = eval( lines )
    for x in range( 0, lines ):
        print( "*" * (x) + "." * (x * 3) + " " + "-" * (x-1) + "*" * (x + 1) )

main()



or this version, also good:

# hw2b.py
# 111a-au Gemma Natori
# Edited by D. Thiebaut
# This program prompts the user for a number and displays 
# a number of lines corresponding to that number.
# Example of user interaction:
# How many lines do you want printed? 3
# *
# *... **
# **...... -***


def main():
    noLines = eval (input ("How many lines do you want printed? "))

    for x in range ( noLines ):
        stars = x
        dots = x * 3
        stars2 = x + 1
        dashes = x - 1
        
        print (stars * "*" + dots * "." + " " + dashes * "-" + stars2 * "*")


main()