Difference between revisions of "CSC111 Homework 2 2011"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <center> <font size="+2">Page under construction!</font> <br \>300px </center> __TOC__ =Problem #1= =Problem #2= I have written a Py...")
 
(Problem #2)
Line 11: Line 11:
 
=Problem #2=
 
=Problem #2=
  
I have written a Python program and have executed it several times in Idle.  I'm including below the output of the program captured from the ''shell'' window:
+
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:
  
 
<code><pre>
 
<code><pre>
>>> ================================ RESTART ================================
 
 
>>> ================================ RESTART ================================
 
>>> ================================ RESTART ================================
 
>>>  
 
>>>  
Line 56: Line 55:
 
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.
 
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.
 +
 +
<code><pre>
 +
>>> ================================ 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
 +
*
 +
>>>
 +
</pre></code>
 
<br />
 
<br />
 
<br />
 
<br />

Revision as of 12:42, 20 September 2011

--D. Thiebaut 13:29, 20 September 2011 (EDT)


Page under construction!
UnderConstruction.jpg

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
*
>>>