2017-10-06 12 views
0

사용자 입력에 따라 왼쪽 또는 오른쪽 방향 화살표를 생성하는 코드를 작성하고 있습니다. 오른쪽으로 향한 화살표에 대한 논리를 알아내는 데 나이가 들었습니다. 이제 왼쪽으로 향한 화살표에 대해 똑같이 할 수 없습니다. 내 코드는이 같은while 루프를 사용하여 화살표를 코딩하는 방법

#Sets accumulator value 
x = 0 
#Prompts user to input desired number of columns 
c = int(input('What')) 
d = str.lower(input ("What direction left (l) or right (r)?:")) 
if d == 'r': 
    while c <= 0: 
     print ("Invalid input.") 
     c = int(input("How many columns? ")) 
    #While x is less than the amount of columns minus one(This is how we get our forward arrow. 
    while(x < c-1): 
     print(x*' ' + '*') 
     #Adds one to x each time loop itterates 
     x +=1 
    #While x is greater than 0 
    while(x >= 0): 
     #Print blank space x number of times and print '*' after that 
     print(x*' ' + '*') 
     #Subtracts one from x each time loop itterates 
     x -= 1 
if d == 'l': 
+0

화살표 어떤 종류의? 화살표로 유니 코드를 사용할 수도 있습니다. – Tomm

+0

while 루프를 사용해야합니다. 간단히 말해서 사용자가 지정한 양의 열을 사용하여 화살표를 인쇄하기 만하면됩니다. 따라서 c == 3 및 d == r이면 3 개의 오른쪽으로 향하는 화살표가 인쇄됩니다. 그러나 왼쪽 화살표 코드를 내려받을 수 없습니다 –

+0

내 대답이 도움이 되었습니까? – Tomm

답변

0

뭔가 질문과 코멘트에서 이해, 당신을위한 해결책이 될 것입니다.

If (c == 3 && d == "r a") { 
    *Your columns + unicode ➡* 
} 

Unicodes 여기에서 찾을 수 있습니다 : http://xahlee.info/comp/unicode_arrows.html