Im trying to make an ASCII graph using python loops.
The goal is for the user to enter an input (formula) [x+1] etc. and print out the graph
the domain and range of the graph only goes from -10 to +10
I managed to get it working, but only for the formula (-x+1), which is (x+1) in my code
I know this problem is because my loop starts printing it from the top, so I would have to change it so it prints the loop in the negative direction but I am stuck on how to combine my graph into a nested loop so it prints it out properly, and then replaces the corresponding place of the function output.
I can give you any more information if you need.
Any constructive thoughts would be much appreciated.
height=20 w=10 x=0 for a in range(0,11): ps= ((" " * w)+('|')+(" " * w)) ps=list(ps) ps[x]="*" x=x+1 pp="".join(ps) print(pp) rs=(('-'*10)+('+')+('-'*10)) rs=list(rs) rs[x]="*" rr="".join(rs) print(rr) for a in range(0,10): ws = ((" " * w)+('|')+(" " * w)) ws=list(ws) y=x+1 ws[y]="*" x=x+1 wp="".join(ws) print(wp)
For anyone too lazy to enter in the code the output looks something like:
* | * | * | * | * | * | * | * | * | *| * ----------+*--------- | * | * | * | * | * | * | * | * | *
(its not showing it correctly on the site, but that is supposed to be a graph of (-x+1), It displays fine when using an interpreter)
This post has been edited by baavgai: 20 March 2013 - 03:26 AM
Reason for edit:: tagged graph, shows better