教授给了我们一个执行正方形的简单代码,我们需要添加/更改代码以输出直角三角形,如下所示。这只是循环代码中的一个简单循环,但如果代码看起来非常混乱/困难,我无法在任何地方找到使用 Python 创建形状的提示或帮助。我需要一个简单的解释来做什么以及为什么我需要做出这些改变。
(在 Python 中创建直角三角形的嵌套循环代码)
给出执行正方形的代码:
画正方形
size = input('Please enter the size: ')
chr  = raw_input('Please enter the drawing character: ')
row = 1
while row <= size:
    # Output a single row
    col = 1
    while col <= size:
        # Output a single character, the comma suppresses the newline output
        print chr, 
        col = col + 1
    # Output a newline to end the row
    print '' 
    row = row + 1
print ''
我需要输出的形状......
x 
x x 
x x x 
x x x x 
x x x x x 
x x x x x x 
x x x x x x x
再次,只是一个简单的代码解释,它是 Python 课程的介绍。