TypeError: float required

The image cannot be sent, therefore: a[i]={(-1)^(i+1)*sin(x)*ln(x)}/{i^2*(i+1)!}

Task:
It is necessary to find a1, a2, ..., an.
n is natural and given.

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 
+7
source share
1 answer

It looks like you are using Python version 3.x. The result of calling input is a string taken from the keyboard, and you go to the math.sin(...) function. float(x) converts x to float but does not save the converted value anywhere, so change:

 float(x) 

in

 x = float(x) 

to get the correct behavior of your code.

+8
source

All Articles