2017-02-10 57 views
-5

使用嵌套循環編寫程序來繪製此模式。 (14)底部頁你如何使用嵌套循環在Python中創建這個形狀?

+0

請解釋* *如何你用起來麻煩嗎?你不明白問題在問什麼(即嵌套循環等)?請*類型*或*文字*複製到你的問題,所以我們沒有通過PDF文件挖找問題14 .. – davedwards

+0

歡迎StackOverflow上。請閱讀並遵守幫助文檔中的發佈準則。 [在主題](http://stackoverflow.com/help/on-topic)和[如何提問](http://stackoverflow.com/help/how-to-ask)適用於此處。 StackOverflow不是一個設計,編碼或教程服務。 – Prune

+0

特別是,發佈「請爲我做我的作業」是*方式*超出了本網站的範圍。 – Prune

回答

0
for row in range(6):     # this outer loop computes each of the 6 lines 
    line_to_print = '#' 
    for num_spaces in range(row):  # this inner loop adds the desired number or spaces to the line 
     line_to_print = line_to_print + ' ' 
    line_to_print = line_to_print + '#' 
    print line_to_print 

打印輸出:

## 
# # 
# # 
# # 
# # 
#  #