Difference between revisions of "CSC111 Lab 2 solutions 2011"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <source lang="python"> # Solution programs for Lab 2 # D. Thiebaut # # This program is not documented. def challenge1(): # this function gets information from t...")
 
 
Line 6: Line 6:
 
# D. Thiebaut
 
# D. Thiebaut
 
#
 
#
# This program is not documented.
 
  
 
def challenge1():
 
def challenge1():

Latest revision as of 16:57, 14 September 2011

--D. Thiebaut 17:57, 14 September 2011 (EDT)


# Solution programs for Lab 2
# D. Thiebaut
#

def challenge1():
    # this function gets information from the user and prints it back on the screen
    print( "\n\nChallenge 1\n---------------" )
    fname   = input( 'Enter your first name, please: ' )
    lname   = input( 'Enter your last name, please:  ' )
    town    = input( 'Which town were you born in?   ' )
    country = input( 'What country is this in?       ' )
    print( fname, lname + ', of', town + ',', country+', welcome to CSC111!' )
    print()

def challenge2():
    # this functions converts several temperature values from Fahrenheit to Celsius
    print( "\n\nChallenge 2\n---------------" )
    temps = [ 32, 100, 60, 70, 75, 80, 90 ]
    for tempF in temps:
        print( "temperature in degrees F =", tempF )
        tempC = ( tempF - 32 ) * 5 // 9
        print( "temperature in degrees C =", tempC )
        print()

    for tempF in temps:
        tempC = ( tempF - 32 ) * 5 // 9
        print( tempF, "Fahrenheit = ", tempC, "Celsius" )
        
    print()

def challenge3_4():
    # this function ask the user for the place where the temperatures were
    # recorded, and displays them along with the location.
    print( "\n\nChallenge 3\n---------------" )
    temps = [ 32, 100, 60, 70, 75, 80, 90 ]
    city  = input( "What city were the temperatures recorded in? " )
    state = input( "What state is " + city + " in? " )
    
    print( "\n\nThe following temperatures were measured in", city + ", " + state + ":" )
    
    for tempF in temps:
        tempC = ( tempF - 32 ) * 5 // 9
        print( tempF, "F or", tempC, "C" )
        
    print()

def challenge5():
    # displays the temperatures stored in a list on a single line
    # using the end argument of the print function.
    print( "\n\nChallenge 5\n---------------" )
    temps = [ 32, 100, 60, 70, 75, 80, 90 ]
    city  = input( "What city were the temperatures recorded in? " )
    state = input( "What state is " + city + " in? " )
    
    print( "\n\nThe temperatures in", city + ", " + state + " are:", end=' ' )
    for tempF in temps:
        print( tempF, end=', ' )
    print()

    print( "The equivalent temperatures in Celsius are:", end=' ' )
    for tempF in temps:
        tempC = ( tempF - 32 ) * 5 // 9
        print( tempC, end=', ' )
    print()
    

def main():
    challenge1()
    challenge2()
    challenge3_4()
    challenge5()


main()