Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: a float is required

Can't post image, so: a[i]={(-1)^(i+1)*sin(x)*ln(x)}/{i^2*(i+1)!}

The task:
Need to find a1,a2,...,an.
n is natural and it's given.

That's the way I tried to do this:

import math
a=[]
k=0
p=0
def factorial(n):
   f=1
   for i in range(1,n+1):
     f=f*i
   return f

def narys(n):
    x=input('input x: ') #x isn't given by task rules, so i think that is error else.
    float(x)
    k=(math.pow(-1,n+1)*math.sin(x)*math.log10(n*x))/(n*n*factorial(n+1))
    a.append=k

n=int(input('input n: '))
narys(n)
for i in a:
   print(a[p])
   p=p+1
like image 216
user2095559 Avatar asked Feb 21 '13 13:02

user2095559


1 Answers

Seems like you're using Python 3.x version. The result of an input call is a string taken from keyboard, which you pass to a math.sin(...) function. float(x) converts x to float but does not store the converted value anywhere, so change:

float(x)

to:

x = float(x)

to get right behaviour of your code.

like image 106
Rostyslav Dzinko Avatar answered Oct 13 '22 20:10

Rostyslav Dzinko