Xs and Ys

Write another program that uses a for loop. With the loop, make the variable x go from -10 to 10, counting by 0.5. Since you cannot use float numbers (E.g., 0.5) in the range() function, you need to think of another way to accomplish this. Be sure to complete Counting by Halves before you attempt this expercise.

Inside the body of the loop, make another variable y become the current value of x squared. Then display the current values of both x and y.

To get your output to line up like mine, use a tab (\t).

Name the file x_y.py

 x      y
-----------------
-10.0   100.00
-9.5    90.25
-9.0    81.00
-8.5   
-8.0    64.00
...
9.0     81.00
9.5     90.25
10.0    100.00

©2021 Daniel Gallo

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.

Creative Commons License

Adapted for Python from Graham Mitchell’s Programming By Doing