CSCI 110, Spring 2011
Home | | Course Schedule | | Assignments | | Lecture NotesLab 2 solution
# Program: wordCheck.py # Author: Brenda Student # Class: CSCI 110 # Date: 2/4/11 # Assignment: Lab 2 # Purpose: Ask for a word and print out the first letter # Check for the case where nothing is entered. word = raw_input("Please enter a word: ") if len(word) == 0: print "No characters were entered." else: print "The first letter of the word is: ", word[0]
# Program: square.py # Author: Brenda Student # Class: CSCI 110 # Date: 2/4/11 # Assignment: Lab2 # Purpose: Use a turtle to draw a square. from turtle import Pen as Turtle size = input("What size square would you like? ") yertle = Turtle( ) yertle.forward(size) yertle.right(90) yertle.forward(size) yertle.right(90) yertle.forward(size) yertle.right(90) yertle.forward(size) yertle.right(90)
# Program: drawingChoice.py # Author: Brenda Student # Class: CSCI 110 # Date: 2/4/11 # Assignment: Lab2 # Purpose: Use a turtle to draw and X or an O based on user input. from turtle import Pen as Turtle yertle = Turtle( ) answer = raw_input("Do you want to draw an X or an O? ") if answer == "X": yertle.up( ) yertle.goto(-50, 50) yertle.down( ) yertle.right(45) yertle.forward(141) yertle.up( ) yertle.goto(-50, -50) yertle.down( ) yertle.left(90) yertle.forward(141) elif answer == "O": yertle.up( ) yertle.goto(0, -50) yertle.down( ) yertle.circle(50) else: print "That is not what I asked for!"