0

So I've been working on this for a little bit now and I cant figure it out at the moment, I need to use a function for a for loop to turn a list of numbers into a string. Not entirely sure what I am doing incorrectly. any help would be appreciated. this is the list

[67, 111, 110, 103, 114, 97, 116, 115, 32, 121, 111, 117, 32, 104, 97, 118, 101, 32, 117, 110, 112, 97, 99, 107, 101, 100, 32, 116, 104, 101, 32, 109, 101, 115, 115, 97, 103, 101, 32, 117, 115, 105, 110, 103, 32, 97, 32, 108, 111, 111, 112, 33]

it looks like it does it but in a line and not in a row like "congrats you have unpacked the message using a loop:" https://i.sstatic.net/9ee8k.png

2
  • Hi Fefe, welcome to the site. Please include your code as text in the question, rather than as a screenshot of your editor. If you can, including the output as text is also strongly preferred (screenshots are fine for graphical output, but for output like you have, text would be better). Commented Mar 26, 2020 at 4:36
  • Thanks for the input! i will next time first ever post! I appreciate everyone for the help! Commented Mar 26, 2020 at 4:53

2 Answers 2

3

It should be:

def convert2string():
    for i in list1:
        print(chr(i), end="")

convert2string()

Congrats you have unpacked the message using a loop!
Sign up to request clarification or add additional context in comments.

1 Comment

Don’t forget the parameter for your function
1

Here is the sample code snippet that resolves your problem. You can update it by adding more punctuation characters and white space character. Hope this helps you.

data = [67, 111, 110, 103, 114, 97, 116, 115, 32, 121, 111, 117, 32, 104, 97, 118, 101, 32, 117, 110, 112, 97, 99, 107, 101, 100, 32, 116, 104, 101, 32, 109, 101, 115, 115, 97, 103, 101, 32, 117, 115, 105, 110, 103, 32, 97, 32, 108, 111, 111, 112, 33]

white_spaces=[9,10,13,32]
for i in data:
  if (i >=65 and i <=90)or (i>=97 and i<=122) or (i in white_spaces):
    print("%c"%(i), end='')

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.