Rambo partyush
Rambo partyush

Reputation: 83

can't multiply sequence by non-int of type 'float' error?

I am trying to do a simple calculation (which later will be done on an array) and getting the aforementioned error.

can't multiply sequence by non-int of type 'float'

8.99*[-(math.log(1-0.5))**(1/2.87)]

Upvotes: 0

Views: 166

Answers (2)

Deepstop
Deepstop

Reputation: 3807

The square brackets turn the result of -(math.log(1-0.5))**(1/2.87) into a list with a single element. The error message is due to the "multiplication" of the list by 8.99. The * operator when applied to a list means to repeat the list elements that many times and to create a new list. e.g. 5 * [1] becomes [1, 1, 1, 1, 1]. Python is complaining that you can't repeat the elements 8.99 times.

You can just remove the square brackets to get a valid answer

8.99 * -(math.log(1 - 0.5)) ** (1 / 2.87)

Upvotes: 3

clubby789
clubby789

Reputation: 2723

You're trying to multiply a list (denoted by square brackets) as a number. Try

8.99*(-(math.log(1-0.5))**(1/2.87)) instead.

Upvotes: 1

Related Questions