• Register
1 vote
3.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

Please log in or register to answer this question.

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,260 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
1 answer 38 views
38 views
Problem: why this happened ? how can i fix it : typeerror: an integer is required (got type str).
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 14 views
14 views
Problem: after upgrading to 3.5, I'm getting the: TypeError: a bytes-like object is required, not 'str'
asked Mar 16 ummesalma 29.2k points
0 votes
1 answer 19 views
19 views
Problem: Any help to solve this error: python typeerror: a bytes-like object is required, not 'str'
asked Mar 15 Wafa Abu Yousef 6.1k points
0 votes
2 answers 1.3K views
1.3K 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
0 votes
1 answer 11 views
11 views
Problem: I created a function that runs a for loop over the squared max of the inputs, and by all accounts my code is correct...and yet it still asks for float inputs.
asked Apr 24 zayed1 61.8k points
0 votes
1 answer 5 views
5 views
Problem: What caused the error"TypeError: range() integer end argument expected, got float " ?
asked Apr 24 zayed1 61.8k points
0 votes
1 answer 96 views
96 views
Problem: Hi there! I am a noob and I have got an assignment in which I have to take two numbers as input from users and print the even numbers that lie between two numbers. I wrote the following program: starting = input("Enter the starting number: ") ending = ... : TypeError: 'str' object cannot be interpreted as an integer I have no idea what is wrong with my program. Can anybody here help me?
asked Dec 21, 2020 Code Learner 9.8k points
0 votes
1 answer 12 views
12 views
Problem: I'm only new, so don't be too harsh if this is really obvious, but why am i getting this error? >>> Enter muzzle velocity (m/2): 60 Enter angle (degrees): 45 Traceback (most recent call last): File "F:/Python31/Lib/idlelib/test", line 9, in <module> range() File " ... (2*(x*x))((decimal(math.zsin(y)))*(decimal(math.acos(y)))))/2) TypeError: can't multiply sequence by non-int of type 'str'
asked Apr 18 munim01 21k points
0 votes
1 answer 11 views
11 views
Problem: I cannot figure out a problem I am having with code written in Python 2.7. I am converting the references to ints, but I keep getting a type exception bad operand type for unary +: 'str'. Can anyone assist?
asked Mar 16 ummesalma 29.2k points