• Register
1 vote
1.4k views

Problem:

I have a piece of code in python and I want to print a list of integer in ASCII. The problem comes once I hit the run button. I don’t know what wrong goes with it. It throws back an error: typeerror: an integer is required (got type str)

n=list(str(12345))
for q in n:
    print(chr(q))

Here is my code snippet. Where I am doing the wrong things? Could you please figure it out?

Thanks.

12 7 7
15,250 points

2 Answers

1 vote

Solution:

You have declared a list with string type and passing it to char() function. You need to cast it to integer type while passing the value through the char() function.

Like this:

n=list(str(12345))
for q in n:
    print(chr(int(q)))

Now, this looks like what you were wanting. Give it a try and post your feedback here.

Thanks.

13 9 6
94,240 points
0 votes

Solution:

You are passing a string value into the chr() function. This must work:

a=list(str(12345))
for q in a:
    print(chr(int(q)))

#The above code will work but this will print out characters, as 1-5
# in the ASCII table are not visible characters.

a = [65,66,67,68,69]
for q in a:
    print(chr(q))

At the time you did x = F.relu(self.lstm(inputs)) in your forward pass, you forgot to give the lstm with hidden and cell units.

10 6 4
31,120 points

Related questions

0 votes
2 answers 934 views
934 views
Problem : I am new to Py 3.5. This code was working properly in Python 2.7: with open(fname, 'rb') as f: lines = [x.strip() for x in f.readlines()] for line in lines: tmp = line.strip().lower() if 'some-pattern' in tmp: continue # ... code After upgrading to 3.5, I'm getting the: TypeError: a bytes-like object is required, not 'str'
asked Oct 22, 2019 peterlaw 6.9k points
1 vote
1 answer 49 views
49 views
Problem: I wrote the following program in python and it throws me the error message: Please enter your first number: 10 Please enter your secoend number: 5 Addition of your numbers 105 Traceback (most recent call last): File "ires.py", line 9, in <module> ... some wong output and then it throws the error message. Is there any problem in my program thats causing this error? Thanks in advance.
asked May 12 samhaz 5k points
1 vote
1 answer 103 views
103 views
Problem: Hi all This is a question from a noob who started coding a few hours back. print("Hello") print("name") print("hello") print("Let's do some math!") print(5 + "a") print("5 + 5") print("Thanks for playing along!") It says, &ldquo;typeerror: unsupported operand type(s) for +: 'int' and 'str'&rdquo; What does it mean?
asked Mar 9 Gavin 15.3k points