Difference between revisions of "CSC111 Homework 6 2014"
(→Submission) |
|||
Line 67: | Line 67: | ||
Submit your program to [http://cs.smith.edu/~thiebaut/111b/submit6.php| cs.smith.edu/~thiebaut/111b/submit6.php]. | Submit your program to [http://cs.smith.edu/~thiebaut/111b/submit6.php| cs.smith.edu/~thiebaut/111b/submit6.php]. | ||
<br /> | <br /> | ||
+ | <!-- | ||
+ | =Solution= | ||
+ | <br /> | ||
+ | <source lang="python"> | ||
+ | def printBlock2( visible ): | ||
+ | if visible==True: | ||
+ | print( "###", end="" ) | ||
+ | else: | ||
+ | print( "...", end="" ) | ||
+ | |||
+ | def printLine( visibility, dim ): | ||
+ | for i in range( dim ): | ||
+ | printBlock2( visibility ) | ||
+ | visibility = not visibility | ||
+ | print() | ||
+ | |||
+ | |||
+ | dim = int( input( "Enter dimension of board: " ) ) | ||
+ | firstBlack = True | ||
+ | for i in range( dim ): | ||
+ | print( " ", end="" ) | ||
+ | printLine( firstBlack, dim ) | ||
+ | print( " ", end="" ) | ||
+ | printLine( firstBlack, dim ) | ||
+ | print( " ", end="" ) | ||
+ | printLine( firstBlack, dim ) | ||
+ | firstBlack = not firstBlack | ||
+ | |||
+ | </source> | ||
+ | <br /> | ||
+ | --> | ||
<br /> | <br /> | ||
<br /> | <br /> |
Revision as of 19:32, 3 March 2014
--D. Thiebaut (talk) 19:11, 3 March 2014 (EST)
Contents
This assignment can be done individually or in pair. The deadline is on Thursday 3/13/2014 evening at midnight. Because you'll be preparing for the midterm that same week, you have only one program to write this time.
Problem #1
Study the solution programs for the chessboard section of Lab 6. Make sure you understand the program(s). Remember, it's ok to play with programs, to insert additional print statements here and there to see what happens, how the programs behave under different tests.
Your assignment is write a program that asks the user for an integer that is greater than or equal to 0, and that displays a chessboard with that dimension. The chessboard uses a 3x3 block to represent each cell of the board.
Below is an example of how your program should behave if the user enters 8 for the dimension (the user input is in boldface):
Enter dimension of board: 8 ###...###...###...###... ###...###...###...###... ###...###...###...###... ...###...###...###...### ...###...###...###...### ...###...###...###...### ###...###...###...###... ###...###...###...###... ###...###...###...###... ...###...###...###...### ...###...###...###...### ...###...###...###...### ###...###...###...###... ###...###...###...###... ###...###...###...###... ...###...###...###...### ...###...###...###...### ...###...###...###...### ###...###...###...###... ###...###...###...###... ###...###...###...###... ...###...###...###...### ...###...###...###...### ...###...###...###...###
Here is another example where the user enters 1:
Enter dimension of board: 1 ### ### ###
Here is still another example where the user enters 0:
Enter dimension of board: 0
The program does not output anything for a board, which is the correct output for dimension 0.
Requirements
- Call your program hw6a.py
- Make sure your program keeps on prompting the user as long as the number entered is negative. Only 0 and positive numbers should be accepted.
- The blocks of the board should always be 3x3 characters. I used dots to represent white blocks, but you can use spaces if you prefer.
Submission
Submit your program to cs.smith.edu/~thiebaut/111b/submit6.php.