2015-10-05 2399 views
0

我想從我已經擁有的矩形中製作一個平行四邊形,但我不知道如何在字符前添加空格。我的代碼是:如何在python上製作一個平行四邊形

l=int(input("Enter the lenght of the rectangle: ")) 
w=int(input("Enter the width: ")) 
c=str(input("Enter the character: ")) 
def print_rect(l, w, c): 
    for a in range(w): 
     print(l*c) 
print_rect(l, w, c) 

我已經試過

for n in range(l-1) 
print("")` 

,但我不知道如何實現它,或者它實際上會工作

回答

0

你沒有定義N種。 對於空間,使用你循環計數器:

def print_rect(l, w, c): 
    for a in range(w): 
     print(a*" ", l*c) 
+0

最後,我想你切換你的長度和寬度。 – Prune

+0

它應該是l * c,而不是n * c,對不起,我正在搞這個讓平行四邊形工作,我沒有修復它。而且,這只是在前面增加了一個空間。我試圖說明,如果寬度爲5,第一行有4個空格,第二行有3個空格,依此類推。 – Rodblt2221

+0

細 - 然後只需將_a *「」_中的'a'更改爲您想要的值。在我的環境中,它做了一個非常漂亮的矩形。如果遇到問題,請更新您的代碼並輸出主要問題。 – Prune