3
我需要一些幫助,試圖解決這個打印三角形,現在它保持垂直僅打印如何使用循環
height = int(input("Height of triangle: "))
for x in range(height):
for y in range(height):
print("#",end = '')
print()
我需要一些幫助,試圖解決這個打印三角形,現在它保持垂直僅打印如何使用循環
height = int(input("Height of triangle: "))
for x in range(height):
for y in range(height):
print("#",end = '')
print()
這裏是我的解決方案,它包括使用蓄電池:
height = int(input("Height of triangle: "))
count = 0
for i in range(height-1):
print('#' + ' '*count + '#')
count += 1
print('#'*height)
height = 6
for rowIndex in xrange(height-1):
row = [' ']*height # yields array of size height
row[0] = row[rowIndex+1] = '#'
print (''.join(row)) # This makes string from array
print ('#'*height) # Print lower side of triangle
您還可以刪除 「+1」 第5行以獲得更多的 「前衛」 TRIANG LES。
'對於範圍(x)中的y''會給你動態的行長度! – schwobaseggl
那些不是很好的三角形。你確定你不想在頂部和右下角的頂點? –
我嘗試了範圍(x)中的y,但它的工作原理是什麼,但是您知道如何獲得三角形中間的空間嗎? – Miryloth