CMSC 201

Winners

Lecture Instructor Team Winning Code
Lecture 1

Introduction to
Computer Science
Using Python Part II
Lupoli Catherine Rassbach
James Marchant
Keith Cheng
Minhaz Mahmud
1. Declare variables <currentYear>, <gradYear>, <yearsLeft>
2. Prompt user for current year
3. User inputs current year, input stored in variable <currentYear>
4. Prompt user for graduation year
5. User inputs graduation year, input stored in variable <gradYear>
6. Perform <gradYear> - <currentYear>, store value in <yearsLeft>
7. Display <yearsLeft>
    
(Line 1 isn't necessary)
Block Group 1:
Emily Colby
Lewis Gould
Chris Boyer
Matt Burton
Winner
Lecture 2

Numbers
Block Group 5:
Christopher Lense
Paula Skidmore
Victoria Myers
Daniel Bitner
Shawn McWilliams
Winner
Lecture 3

List and for Loops
Lupoli Leslie McNeely
Ijeoma Eze-Wachuku
numbers = []
for i in range(10):
    number = input("Enter a number: ")
    numbers.append(number)

total = 0.0
for number in numbers:
    total += number
average = total / len(numbers)

numbers.sort()
print "Minimum =", numbers[0]
print "Maximum =", numbers[-1]
print "Average =", average
print "Total =", total
    
Block Group 21:
Graham Antoszewski
Max Barnhart
Reza Hassan
Don Wesloh

Group 3:
Griffin Yourick
Cameron Moten
Kevin Sears
Gavin Lebo
Winner 1
Winner 2
Lecture 4/5

Strings
Lupoli Patrice Lincoln
Deborah Firestone
Christina Stevens
Matt Fertig
# File: ascii.py
# Date: 2/15/12
# Names: Patrice Lincoln, Deborah Firestone, Christina Stevens, Matt Fertig
# Instructor: Lupoli
# Description: This program prints the ASCII value of each letter in a string on
# a single line

def main():
    user_input = raw_input("Please enter a string less than 10 characters long: ")
    for char in user_input:
        print ord(char),

main()
    
Block Group 12:
Mark Nussear
Aroush Anis
Ahsan Rizvi
Ryan Albrecht
# Filename: ascii.py
# Written by: Group 12
# Date: 02/16/2012
# Section: All
#
# This program will print out the ascii value of each letter in a string
# all on the same line.  The user must enter a string of less than 10
# characters or it will keep asking.

def main():

   val = 10

   while val >= 10:
      word = raw_input("Please enter a string of less than 10 characters: ")
      print "The string you entered is: ", 

      val = 0

      for char in word:
         val += 1
         print char,

      if val >= 10:
         print "\nERROR!\n You did not enter less than 10 characters: "

   print "\nThe ascii values are: ", 

   for char in word:
      print ord(char),

main()
Lecture 6

Conditionals and Booleans
Block Group: 14
Seongmin Kang
Sherill Smallwood
Junling Song
Neil Anderson
def main(): 
    print "This program tells you if there is a hurricane and what category it is" 
    # read input from user 
    windSpeed = input(Please enter the current wind speed: ") 
    if windSpeed < 74: 
        print "This is not a hurricane" 
    elif windSpeed <= 95: 
        print "This is a category 1 hurricane" 
    elif windSpeed <= 110: 
        print "This is a category 2 hurricane" 
    elif windSpeed <= 130: 
        print "This is a category 3 hurricane" 
    elif windSpeed <= 155: 
        print "This is a category 4 hurricane" 
    else: 
        print "This is a category 5 hurricane" 
 
main()
Lupoli Mona Prakash
Dennis Wu
Zachary Bachman
# Mona, Dennis, Zachary
# This program gives the categories of hurricane
# 2/22/12

def main():
    # get user input and save in variable speed
    speed = input("Enter wind speed in mph: ")
    if (speed < 0):
        print "Invalid input"
    elif (speed < 74):
        print "No hurricane"
    elif (speed < 96):
        print "Category 1: Minimum"
    elif (speed < 111):
        print "Category 2: Moderate"
    elif (speed < 131):
        print "Category 3: Extensive"
    elif (speed < 156):
        print "Category 4: Extreme"
    else:
        print "Category 5: Catastrophic"

main()
Lecture 8

Functions
Block Group: 20
Robert Kappesser
Wayne Wiggins
# Filename: even.py
# Written by: see left
# Date: 3/1/12
# Section: 9

# printGreeting() greets the user to the program
# Inputs: none
# Output: none
def printGreeting():
    print "Welcome to the even integer program"

# isEven(num) determines if an integer is even or odd
# Inputs: num
# Output: Boolean (True or False)
def isEven(num):
    if num % 2 == 0:
        return True
    else:
        return False

def main():

    printGreeting()

    min = input("Enter a starting number: ")
    max = input("Enter an ending number: ")

    for num in range(min, max + 1):
        if isEven(num) == True:
            print num,

main()
            
Lupoli Catherine Rassbach
James Marchant
Keith Cheng
Minhaz Mahmud
# File: even.py
# Written by: Catherine, Brittany, James, Minhaz
# Section: 1
# Date: 2/27/12
# Description: Prints the even numbers in a range

# prints a greeting
def printGreeting():
    print "Hi. This will print even numbers."

# determines whether a number is even
def isEven(value):
    if (value % 2 == 0):
        return True
    else:
        return False

def main():
        
Lecture 9

Tracing Functions
Lupoli Steven Stancil
Austin Weed
Adam Huganir
main(): a   b   c   f(): a   b   c   g(): a   b   c   output
--------------------------------------------------------------------------------
        0          |                |                                   
--------------------------------------------------------------------------------
            0      |                |                                          
--------------------------------------------------------------------------------
                0  |                |                                   
--------------------------------------------------------------------------------
                   |     0          |                                   
--------------------------------------------------------------------------------
                   |         5      |                                   
--------------------------------------------------------------------------------
                   |                |         5                         
--------------------------------------------------------------------------------
                   |                |             12                    
--------------------------------------------------------------------------------
                   |                |     10                            
--------------------------------------------------------------------------------
                   |                |                 g: a = 10, b = 5, c = 12
--------------------------------------------------------------------------------
                   |             10 |                   
--------------------------------------------------------------------------------
                   |                |                 f: a = 0, b = 5, c = 10
--------------------------------------------------------------------------------
        10         |                |                   
--------------------------------------------------------------------------------
                   |                |         10        
--------------------------------------------------------------------------------
                   |                |             17    
--------------------------------------------------------------------------------
                   |                |     15            
--------------------------------------------------------------------------------
                   |                |                 g: a = 15, b = 10, c = 17
--------------------------------------------------------------------------------
                15 |                |                   
--------------------------------------------------------------------------------
                   |                |                 main: a = 10, b = 0, c = 15
Lecture 10

I/O
Block Group 10:
Andrew Konsowski
Paul Giro
Aleksander Kaplan
def printGreeting():
    print "This will count lines in a file"

import string

def main():
    count = 1
    printGreeting()

    infile = open("ioExercise.txt", "r")
    outfile = open("ioExercise.num.txt", "w")

    for line in infile:
        linecount =  "%2s %s" % (count, line)
        count = count + 1
        outfile.write(linecount)

    infile.close()
    outfile.close()

main()
Lupoli Austin Weed
Sean Ennis
Steven Stancil
Adam Huganir
# File: io.py
# Author: see coversheet
# Date: 3/5/12
# Description: This program will adda  line number
#              before each line in ioExercise.txt

def main():
    # get file input and output
    infile = open("ioExercise.txt", "r")
    outfile = open("ioExercise.num.txt", "w")

    # initialize counter i
    i = 0
    for line in infile:
        i += 1
        outfile.write("%2d %s" % (i, line))

    infile.close()
    outfile.close()

main()
Lecture 11/12

Loops
Lupoli Eric Eng
Kevin Zhang
Erin Morris
Mark Aliprando
def square(length):
    line = ''
    for i in range(length):
        for i2 in range(length):
            line = line + '*'
        line = line + "\n"
    print line

def triangle(length):
    line = ''
    for i in range(length):
        for i2 in range(i + 1):
            line = line + '*'
        line = line + "\n"
    print line

def main():
    length = input("Input square size length: ")
    square(length)
    length = input("Input isosceles size length: ")
    triangle(length)

main()
Lecture 16/17

Top-Down Design
Lupoli Matthew Reeping
John Wright
Winner
Lecture 16/17

Random Numbers
Lupoli Jonathan Ko
Hadia Aqeel
Matthew Barteau
# This program writes 100 randomly generated numbers between 1 and 19 into numbers.dat
from random import *

def main():
    outfile = open("numbers.dat","w")
    for i in range(100):
        number = randrange(1,20)
        outfile.write("%d\n" % number)
    outfile.close()

main()
Lecture 18/19

Python's Data Types
Lupoli Seth Blazucki
Sam Chief Greenberg
def main():
    filename = raw_input("Enter the filename: ")
    zipdict = dict()
    infile = open(filename, "r")
    for line in infile:
        zipdict[line.split()[0]] = line.split()[-1]
    userinp = raw_input("Enter a location (Q to quit): ")
    while userinp != "Q":
        print zipdict.get(userinp)
        userinp = raw_input("Enter a location (Q to quit): ")

main()
Lecture 20

Abstract Data Types
Lupoli Cory Womack
Michael Vu
def enqueue(items, items):
    items.append(item)

def dequeue(items):
    size = len(items)
    if size < 0:
        dequeued = items[0]
        del(items[0])
        return dequeued
    else:
        return "empty queue"
Lecture 25/26

Defining New Classes
Lupoli Jenna Gallagher
Abdullah Hassan
William Krozack
Brendan Born
class Cube:
    def __init__(self, length):
        self.length = float(length)

    # accessors
    def getLength(self):
        return self.length

    # other methods
    def findSurfaceArea(self):
        return 6 * self.length * self.length

    def findVolume(self):
        return self.length * self.length * self.length

Thursday, 17-May-2012 17:55:51 EST