Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
homework help
#1
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

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
Reply


Messages In This Thread
homework help - by maisaadabbah - Jan-13-2020, 03:35 PM
RE: homework help - by jefsummers - Jan-13-2020, 11:16 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020