【Python實作】製作一個星星符號組成的長方形
Python實作_製作一個星星符號組成的長方形
目的:練習巢狀迴圈
條件:讓使用者輸入列(row)與行(columns),便列印出一個由星星(***)組成的row x columns的長方形。
#程式開始
rows = int(input("Enter number of
rows: "))
cols = int(input("Enter number of
columns: "))
for i in range(rows):
for j in range(cols):
print("*",end=" ")
print("")
#程式結束
(1)程式運行結果:
Enter number of rows: 3
Enter number of columns: 4
* * * *
* * * *
* * * *
(2)程式運行結果:
Enter number of rows: 12
Enter number of columns: 16
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
留言
張貼留言