【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

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * *

 

留言

這個網誌中的熱門文章

常見的化痰粉愛克痰(小鳥粉)怎麼吃?|化痰粉成人及小孩的使用劑量|紅色與藍色比較

麻將教學懶人包|從規則到牌理的完整觀念整理(附實戰心得)

麻將新手必看!不知道聽什麼牌怎麼辦?超多種實戰聽牌範例,教你怎麼判斷胡牌機會