如何使用for循环打印三角形 [英] How to print a triangle using for loops
本文介绍了如何使用for循环打印三角形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些帮助来解决这个问题,目前它仅保持垂直打印
I need some help trying to solve this, right now it keeps printing vertically only
height = int(input("Height of triangle: "))
for x in range(height):
for y in range(height):
print("#",end = '')
print()
推荐答案
这是我的解决方案,它涉及累加器的使用:
Here's my solution, it involves the use an of accumulator:
height = int(input("Height of triangle: "))
count = 0
for i in range(height-1):
print('#' + ' '*count + '#')
count += 1
print('#'*height)
这篇关于如何使用for循环打印三角形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文