CSCI 110, Spring 2011
Home | | Course Schedule | | Assignments | | Lecture NotesLaboratory 2
Due at the end of today's class
Problem #1.
Last week you wrote a Python program (named word.py) which input a string and printed out some information about the text that was entered. One piece of information was the first letter of the word.
The following two lines of code will accomplish this:
A sample session might look like the following:
Please enter a word: friends
The first letter of the word is f
Note: User input is underlined.
Notice that when the user does not enter anything, but hits the return key immediately after the prompt, the program above generates an error. (Try it!)Write a program, named wordCheck.py, that uses a conditional to test whether the length of the word entered is zero. If it is, the program should print out:
Otherwise, it should print out the first letter of the word as in the above example.
A sample session in which the user did not enter any characters might look like the following:
Please enter a word:
No characters were entered.
Problem #2.
Write a Python program, called square.py, that asks the user for a size and uses a turtle
to draw a square with a side length of that size.
To use a turtle, first import the turtle class using the line:
Next you should prompt for and read in the size of the square.
Next, create a turtle object using the statement:
Problem #3.
Write a Python program, named drawingChoice.py, that asks the user if they want to draw an X or an O.
If the user enters "X", your program should use a turtle object to draw an X.
If the user enters "O", your program should use a turtle object to draw an O.
If the user enters anything else, your program should print:
The following Python code will draw an 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)The following Python code will draw an O:
yertle.up( ) yertle.goto(0, -50) yertle.down( ) yertle.circle(50)Use a conditional to determine what to draw.
What To Turn In.
A printed listing of each lab program.
Be sure that your name is in the program prologue's comment section of EACH program.
Reminder.
Be sure to save a copy of each program on your P:\ drive.
You are responsible for keeping a copy of every program until the graded assignment is handed back.