I am trying to make write a code that makes a graph of front and backward slashes based upon the values that user input
def setNums(num_filter):
if num_filter[0] != 0:
num_filter.insert(0,0)
else:
pass
arranged_values = [-value if counter%2 == 0 else value for counter,value in enumerate(num_filter)]
return arranged_values
def printLines(num_filter, total_lines):
su = 0
sd = 0
li = -1
for counter,num in enumerate(num_filter):
for z in range(num):
if (counter%2 != 0):
li += 1
total_lines[li] += (" "*su+"/")
try:
su = len(total_lines[li])-len(total_lines[li+1])
except IndexError:
pass
sd = 0
else:
total_lines[li] = total_lines[li]+(" "*sd+"\\")
sd = len(total_lines[li])-len(total_lines[li-1])
li -= 1
su = 0
return '\n'.join(total_lines[::-1])
def main():
numbers = input("Enter numbers (seperated by space): ")
num_filter = [int(num) for num in numbers.split()]
nums_arranged = setNums(num_filter)
total_lines = ['']*max([sum(nums_arranged[0:num:1]) for num in range(0, len(nums_arranged)+1)][1:]
output = printLines(num_filter, total_lines)
print ("Printing graph... \n", output)
It works well when the graph is going up but when the graph is going down then it pastes downside slashes on the top of the graph.
This code basically takes user input of multiple numbers like 2 3 4 2 4 1 3 6 then seperates odd index values and even index values by putting negative sign.. then with the cumulative sum, it predicts the lines needed (thats where the problem is I think) then based on the values of numbers it prints slashes in arrangement.
The output I am expecting is like this:

The output I am getting is like this:

2 3 4 2 4 1 3 6is supposed to mean for the solution? Is it up 2, then down 3, then up 4, etc.?