At some point in math class, after graphing inequalities as shown in this lesson, you then move on
to graphing inqualities that take up the entire xy-plane. They'll be instructions to "graph inequalties" like this: $y< x+5$,
$y\ge|2x-7|$, or $y<|x-1|$. These can be particularly hard when they involve absolute values. Never fear though! These are very straightforward
to visualize using the computer, which is what this lesson is about.
To study the graph of such inequalities we'll use decimal random numbers. Suppose we chose a random $(x,y)$ point
on our graph. Since $x$ on our screen runs from -250,250 and $y$ between -180 and 180, we'll use this range for our random range of each. Next
once $x$ and $y$ are chosen, we'll use an if statement to test the truth of the inequality. If it is true, then we'll plot a point at
the given $(x,y)$ position.
For example, suppose we were trying to plot $y<2x+1$. With our two random choices for $x$ and $y$, we'll test if it is true that $y<2x+1$.
If it is, then we'll plot a point at that $(x,y)$ point. If not, we'll simple choose a new random $(x,y)$ point and try the test again. After many
runs (around 1,000 or so), our plotting area will be the answer to "plot in inequality $y<2x+1$.
Now you try. Put some inequality to test in the if statement.
Type your code here:
See your results here:
The code here will not run. You have to fix the if statement to test the inequality on which you are working.
Show a friend, family member, or teacher what you've done!
Here is a share link to your code:
Does your code work? Want to run it on your iPhone?
Here's your code:
Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.
Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into
Then click the "Use on iPhone" button that you'll see.