Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 homework help maisaadabbah Unladen Swallow Posts: 1 Threads: 1 Joined: Jan 2020 Reputation: 0 Likes received: 0 #1 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 ```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 ``` jefsummers Minister of Silly Walks Posts: 301 Threads: 1 Joined: May 2019 Reputation: 26 Likes received: 44 #2 Jan-13-2020, 11:16 PM Couple things to start. The assignment says your PolCal should take one argument, not two. In line 20 you will then call it on b, which is the list you generated in the first part. Second, whenever you are tempted to use range(len(x)), don't. You can say for i in li and it does the same thing, easier to read, easier to debug. It is also a very good idea to use descriptive variable names. We've come a long way from Fortran where variables starting with "i" through "n" were integers and the rest floats. PolCal also needs to return two lists. You are returning one single value. Read that part of the assignment again and think about what you want to generate, and then how. « Next Oldest | Next Newest »

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)