0
 result = [None] * k
 setsize = 21        # size of a small set minus size of an empty list
 if k > 5:

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

1
  • 2
    We will have to see how you're calling into random too. Commented Mar 30, 2020 at 11:05

2 Answers 2

1

If this line is producing the error then it's obvious.

k is a float and you can't multiply a list with a float. So, if you cast your float k to int, the code runs without error.

 k = int(k)
 result = [None] * k
 setsize = 21        # size of a small set minus size of an empty list
 if k > 5:

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

I assumed that random.py was Pythons random.py and changing that wouldn't be the best of ideas. If the OP called his own file random.py your answer will help, but I'd strongly suggest not to use this file name.
Instead of saying "it's obvious", it may be helpful to the asker if you give some kind of explanation about what's going on here
Don't think it's the python random module, no reason to edit that. I agree, random.py is a very bad choice, it can mess up the namespace.
I think I provided two examples to show the contrast.
0

You cannot multiply a list by a float type and it seems like 'k' is a float type. Try converting to int type before.

result = [None] * int(k)
setsize = 21
if k > 5:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.