user2095559
user2095559

Reputation: 81

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

Upvotes: 8

Views: 83543

Answers (1)

Rostyslav Dzinko
Rostyslav Dzinko

Reputation: 40755

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.

Upvotes: 7

Related Questions