2015-10-05 2397 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