TypeError: can't multiply sequence by non-int of type 'bytes' in Python

Dung Do Tien Oct 09 2021 0

Hello you guys, I beginner in Python and I'm also studying more about Python.

I want to multiply some bytes data type to get a random text. My block of code as below:

 symbol = b'j|encoding: hexdump'
play_symbol = b'emoji.txt0000000 f0'
bonus_number = int(input("Enter bonus number:"))

full_text = (symbol + play_symbol) * bytes(bonus_number)

print(full_text)

But I get an exception throw TypeError: can't multiply sequence by non-int of type 'bytes' when I run code above.

 Enter bonus number:9
Traceback (most recent call last):
  File "main.py", line 5, in <module>
    full_text = (symbol + play_symbol) * bytes(bonus_number)
TypeError: can't multiply sequence by non-int of type 'bytes'

And I am using python 3.x

Anyone can explain it to me? How can I solve it?

Thanks for any suggestions.

No answer found.
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close