-1

I'm stuck on this question:

user inputs a word, program outputs the unicode of each letter in the word

this is how the input statement would look:

word = input("Enter a word: ")

Supposing the user enters the word "Cat", the output would look like this:

C: 67
a: 97
t: 116
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
galaxies
  • 63
  • 7
  • Although you've given an example for the output, it doesn't correspond well with the way Unicode strings are described. I suggest something like this [U+0043](https://www.fileformat.info/info/unicode/char/0043/index.htm) [U+0061](https://www.fileformat.info/info/unicode/char/0061/index.htm) [U+0074](https://www.fileformat.info/info/unicode/char/0074/index.htm). That way it is very clear what the input is and the problem reduces to iterating Unicode codepoints (which are numerically the same as the UTF-32 code units, which might be useful if using Python <3.3). – Tom Blodget Jan 08 '19 at 00:12

2 Answers2

0

Use ord().

word = input("Enter a word: ")
for letter in word:
    print(letter + ': ', ord(letter))
Luke DeLuccia
  • 541
  • 6
  • 16
0

Based on your example I guess what you try to output is ASCII values of characters. If so you could check ASCII values using python builtin function ord().

userInput = input("Enter a word: ")

for i in userInput:
    print('{}: {}'.format(i, ord(i)))

Output:

C: 67
a: 97
t: 116
Filip Młynarski
  • 3,534
  • 1
  • 10
  • 22