Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the sum of the ASCII codes of the characters of 'hello'? Run the code.

Problem: What is the sum of the ASCII codes of the characters of 'hello'? Run the code.
print(sum(ord(c) for c in 'hello'))
What is printed?
  1. A. 532
  2. B. 372
  3. C. 52
  4. D. 424

Correct answer: A. 532

h, e, l, l, o have codes 104 + 101 + 108 + 108 + 111 = 532. Upper-case HELLO gives 372, alphabet positions give 52, and counting the repeated l once gives 424.

More Coding Interview Problems questions

Exams that ask this topic