CSC111 Homework 2 2011
--D. Thiebaut 13:29, 20 September 2011 (EDT)
Problem #1
Problem #2
I have written a Python program (hw2a.py) and have executed it several times in Idle. I'm including below the output of the program captured from the shell window:
>>> ================================ RESTART ================================
>>>
How many lines do you want printed? 0
>>> ================================ RESTART ================================
>>>
How many lines do you want printed? 1
*
>>> ================================ RESTART ================================
>>>
How many lines do you want printed? 2
*
*... **
>>> ================================ RESTART ================================
>>>
How many lines do you want printed? 3
*
*... **
**...... -***
>>> ================================ RESTART ================================
>>>
How many lines do you want printed? 10
*
*... **
**...... -***
***......... --****
****............ ---*****
*****............... ----******
******.................. -----*******
*******..................... ------********
********........................ -------*********
*********........................... --------**********
>>>
Your assignment is to write a program that behaves exactly, or as close to the program I have written as possible. In particular, notice that when I entered 0, it didn't print anything. When I entered 1, it printed one line. When I entered 2 it printed 2 lines. 3, 3 lines; 10, 10 lines.
You do not have to worry about the extra space at the beginning of the first line. Your program will be be good even if it prints the first star of the first line in the left most column.
Submission
- Submit your program on beowulf or emmy as follows:
submit hw2 hw2b.py
Problem #3
Same idea as for Problem #2. Reconstruct a program I have written (called hw2c.py) which will behave the same way as a program whose output is shown below.
>>> ================================ RESTART ================================
>>>
Enter a positive number less than 20: 5
Printing a diamond of 5 lines
*
***
*****
*******
*********
*******
*****
***
*
>>> ================================ RESTART ================================
>>>
Enter a positive number less than 20: 4
Printing a diamond of 4 lines
*
***
*****
*******
*****
***
*
>>> ================================ RESTART ================================
>>>
Enter a positive number less than 20: 0
Printing a diamond of 0 lines
>>> ================================ RESTART ================================
>>>
>>>
Enter a positive number less than 20: 1
Printing a diamond of 1 lines
*
>>>