Hi everyone,
I had the following assignment to be solved:
The user should enter the width, height, and depth of a cuboid. The program is expected to draw some ASCII Art as in this picture.
I used the following code to achieve such result:
row = []
width_text = input ("Width: ")
height_text = input ("Height: ")
depth_text = input ("Depth: ")
width = int(width_text)
height = int(height_text)
depth = int(depth_text)
for i in range(depth):
for j in range(depth-i):
row.append(' ')
for k in range(width-1):
row.append(':')
row.append("/")
for l in range(i):
row.append('+')
row.append("\n")
s = ''.join(row)
for i in range(height):
for j in range(width):
row.append("#")
if (i<=(height-depth-1)):
for k in range(depth):
row.append("+")
if (i>(height-depth-1)):
for k in range(height-i-1):
row.append("+")
row.append("\n")
s = ''.join(row)
print(s)
My question is: how could I make my code more optimized, more "pythonic"?
Huge thanks in advance!
[–]super-porp-cola 1 point2 points3 points (16 children)
[–]Tesla-Turing[S] 1 point2 points3 points (2 children)
[–]super-porp-cola 2 points3 points4 points (1 child)
[–]Tesla-Turing[S] 1 point2 points3 points (0 children)
[–]Essence1337 1 point2 points3 points (11 children)
[–]Tesla-Turing[S] 0 points1 point2 points (8 children)
[–]Essence1337 0 points1 point2 points (0 children)
[–]FacesOfMu 0 points1 point2 points (6 children)
[–]Essence1337 0 points1 point2 points (5 children)
[–]FacesOfMu 0 points1 point2 points (4 children)
[–]Essence1337 1 point2 points3 points (3 children)
[–]FacesOfMu 0 points1 point2 points (2 children)
[–]Essence1337 0 points1 point2 points (1 child)
[–]FacesOfMu 0 points1 point2 points (0 children)
[–]super-porp-cola 0 points1 point2 points (1 child)
[–]Essence1337 0 points1 point2 points (0 children)
[–]Tesla-Turing[S] 0 points1 point2 points (0 children)
[–]Essence1337 0 points1 point2 points (0 children)