-2
私の教授がクラスでこのコードを共有しましたが、実際にはわかりません。誰でもこのプログラムで何が起こっているのかを私に説明することはできますか?入れ子ループの場合アスタリスクトライアングル
#Task 1: Prompt the user to input the number of rows of the triangle.
rows = eval(input("How many rows should the equilateral triangle have?"))
#Task 2: Calculate how many asterisks in the last row, write outer loop.
for i in range(rows + 1):
#Task 3: For each outer loop, calculate how many spaces and asterisks need to be printed in each row.
emptySpaces = rows - i
#Task 4: Write inner loop to print spaces and asterisks.
print(' ' * emptySpaces + '* ' * i)
、これは出力が
How many rows should the equilateral triangle have?6
*
* *
* * *
* * * *
* * * * *
* * * * * *
あなたは何を分かりませんか?コードとコメントのリンクを理解していますか? – Zafi
あなたの教授は実際に 'eval()'(int()がうまくいっていた)を何らかの答えキーとして何かを共有しましたか? – TigerhawkT3
また、あなたの教授が授業で何かを共有していた場合、適切な行動の過程はあなたの手を___して___に尋ねることです。それがクラスのためのものです。 – TigerhawkT3