We had to port a program from c to python. The code works but uses a dictionary to solve the problem. This doesn't feel like the right use of a dictionary. Is there a better way?
#!/usr/bin/env python3
def main():
while True:
height = input("Height: ")
try:
height = int(height)
if height >= 0:
break
except:
pass
mtn={}
space_mtn(height,mtn)
hashs_mtn(height,mtn)
print_mtn(height,mtn)
def space_mtn(height,mtn):
for i in range(height):
for j in range(2*height+2):
mtn[i,j]=" "
return
def hashs_mtn(height,mtn):
for i in range(height):
for j in range(height-1,height-i-2,-1):
mtn[i,j] = '#'
for i in range(height):
for j in range(height+2,height+i+3):
mtn[i,j] = '#'
return
def print_mtn(height,mtn):
for i in range(height):
for j in range(height+3+i):
print("{}".format(mtn[i,j]),end="")
print("")
return
if __name__ == "__main__":
main()