-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject10.py
294 lines (247 loc) · 7.24 KB
/
project10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
"""
Course: CS101
File: Project 10
Project: 10
Author: Alfredo Pena
Description:
<Replace this line with what does your project/program do?>
"""
"""
Instructions:
Your project will be implementing a number of functions. Each function
displays a different shape. Your code MUST only use the following functions
that are found in the project code to display anything to the console. (You
may NOT use print statements in the functions you are completing.)
star() displays a '*' character without the new line
fill() displays a '#' character without the new line
space() displays a ' ' character without the new line
newline() displays a new line
Each function is called in the main code found at the bottom of this
project file. Functions contain the sample output that you need to match.
"""
# =========================================================================
# The next four function should not be changed. They should be used in the
# functions that you complete.
# =========================================================================
def star():
""" Display a star without the normal new line """
print('*', end='')
def fill():
""" Display a fill character without the normal new line """
print('#', end='')
def space():
""" Display a space without the normal new line """
print(' ', end='')
def newline():
""" Display a new line """
print()
# =========================================================================
# This is an example function to give you an idea of what the functions
# below it should work like. Your functions will need to call the
# appropriate functions (defined above) to draw the expected shapes.
# =========================================================================
def sampleSquare(size):
""" display a square of stars of the given size
- The example below has size = 6
******
* *
* *
* *
* *
******
"""
print('Sample Square of size', size)
# display the first row of stars
for i in range(size):
star()
newline()
# display the "middle" rows. There are (size - 2) of them
for i in range(size - 2):
# for each row: star, spaces (size - 2 of them), star, newline
star()
for j in range(size - 2):
space()
star()
newline()
# display the last row of stars
for i in range(size):
star()
newline()
# =========================================================================
# The functions below are the ones YOU need to complete.
# Example output is shown for each.
# =========================================================================
def doubleSquare(size):
""" Display a square with sides that are 2 stars thick
- This example has size = 3
******
******
** **
** **
******
******
"""
print('Double Square of size', size)
for number in range(size):
star()
newline()
for number in range(size):
star()
for number in range(size):
newline()
for column in range(2):
star()
for column in range(size - 4):
space()
for column in range(2):
star()
newline()
for number in range(size):
star()
newline()
for number in range(size):
star()
newline()
def halfAndHalf(size):
""" Display a square that is half filled
- This example has size = 6
******
* ##*
* ##*
* ##*
* ##*
******
"""
print('Half and half square of size', size)
for numbers in range(size):
star()
for number in range(size):
newline()
for column in range(1):
star()
for column in range(size-4):
space()
for column in range(2):
fill()
for column in range(1):
star()
newline()
for numbers in range(size):
star()
newline()
def rightTriangle(size):
# """ Display a right triangle
# - This example has size = 4
# *
# **
# ***
# ****
# """
print('Right triangle of size', size)
for numbers in range(size):
newline()
for numbers in range(size - numbers):
space()
for numbers in range(size - numbers):
star()
newline()
def twoTriangles(size):
""" Display two triangles
- This example has size = 5
***** *
**** **
*** ***
** ****
* *****
"""
print('Two triangles of size', size)
for numbers in range(size):
newline()
for stars1 in range(size - numbers):
star()
for i in range(2):
space()
for numbers in range(size - stars1):
star()
newline()
def hockeyStick(handleLen, bladeLen):
""" Display a hockey stick where the handle is of length handleLen
and the blade is of length bladeLen.
- This example has handleLen = 6, bladeLen = 7
*
*
*
*
*
*
*******
"""
print('Hockey stick of size', handleLen, 'and', bladeLen)
for numbers in range(handleLen):
newline()
for numberofSpaces in range(numbers):
space()
for numberOfStars in range(1):
star()
for starsOfBlade in range(bladeLen):
star()
newline()
def squareInSquare(outerSize, innerSize):
""" Display a small square inside a larger square
- This example has outerSize = 10, innerSize = 4
**********
* *
* *
* **** *
* **** *
* **** *
* **** *
* *
* *
**********
"""
print('Outer and inner square of size', outerSize, 'and', innerSize)
for roof in range(outerSize):
star()
for inside1 in range(int((outerSize - innerSize)/2)- 1):
newline()
star()
for spaces in range(outerSize - 2):
space()
star()
for inside2 in range(innerSize):
newline()
star()
for windowSpaces in range(int((outerSize - innerSize)/2)-1):
space()
for windowStar in range(innerSize):
star()
for windowSpaces in range(int((outerSize - innerSize)/2)-1):
space()
star()
for inside1 in range(int((outerSize - innerSize)/2)- 1):
newline()
star()
for spaces in range(outerSize - 2):
space()
star()
newline()
for floor in range(outerSize):
star()
newline()
# =========================================================================
# Main code - Don't change any code below
sampleSquare(4)
sampleSquare(5)
doubleSquare(6)
doubleSquare(9)
halfAndHalf(6)
halfAndHalf(10)
rightTriangle(4)
rightTriangle(6)
twoTriangles(3)
twoTriangles(7)
hockeyStick(4, 2)
hockeyStick(6, 7)
squareInSquare(10, 4)
squareInSquare(12, 6)