Jan-13-2020, 03:35 PM
hey :)
I am totally a beginner taking a python course for college, ill be happy if anyone can direct me in writing the code.
this is so far what i have already coded.
the homework:
A)write the function RandCoef with no arguments, the function must return a random integer from 1 to 10,
also returns a random list of numbers between 0 and 1 where the length equals to N.
B)write the function RandPolCal that takes the random list from A as an argument, the function must return 2 lists - (1) a list of X in the section [-10,10], (2) a list with the same length of the random polinom's values in each one of the values of the X list.
ive already coded (A) but i dont know how to do (B), i thought about nested function but coudlnt write it
I am totally a beginner taking a python course for college, ill be happy if anyone can direct me in writing the code.
this is so far what i have already coded.
the homework:
A)write the function RandCoef with no arguments, the function must return a random integer from 1 to 10,
also returns a random list of numbers between 0 and 1 where the length equals to N.
B)write the function RandPolCal that takes the random list from A as an argument, the function must return 2 lists - (1) a list of X in the section [-10,10], (2) a list with the same length of the random polinom's values in each one of the values of the X list.
ive already coded (A) but i dont know how to do (B), i thought about nested function but coudlnt write it
import random as r import numpy as np import matplotlib.pyplot as plt #returns the value of the polinom in a specific point (x) def PolCal(x,li): val = 0 for i in range(len(li)): val+=(x**i)*(li[i]) return val def RandCoef(): N = r.randint(1,10) L = [r.random() for i in range(N)] return N,L a,b = RandCoef() print a print b