CSC111 Homework 2 Solutions 2011

From dftwiki3
Revision as of 12:36, 3 October 2011 by Thiebaut (talk | contribs) (hw2b.py)
Jump to: navigation, search

--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()