Objective
Develop a Python program to "draw" the graph of the function y = (x-4)^2 for integer values of x ranging from -1 to 8. It will display as many asterisks on the screen as the value obtained for "y", like this:
*************************
****************
*********
****
*
*
****
*********
****************
Example Python Exercise
Show Python Code
# Loop through integer values of x from -1 to 8
for x in range(-1, 9):
y = (x - 4) ** 2 # Calculate the value of y using the given function
print('*' * y) # Print y number of asterisks
Output
***************
****************
***********
******
*
*
****
**********
*****************
***********************
*******************************
Share this Python Exercise