Friday, 2 August 2019

Write a Python program to plot the function y = x2 using the pyplot or matplotlib libraries.


import matplotlib.pyplot as pl
lstx=[]
lsty=[]
num = int(input('How many numbers: '))
for i in range(num):
    x = int(input('Enter number '))
    lstx.append(x)
    y=x**2
    lsty.append(y)
pl.plot(lstx,lsty)
pl.show()

Input

How many numbers: 3
Enter number 1
Enter number 2
Enter number 3

No comments:

Post a Comment