Skip to content

Instantly share code, notes, and snippets.

@solen003
Created July 15, 2018 21:57
Show Gist options
  • Select an option

  • Save solen003/681752c57f8bee735c2f451bab4786fd to your computer and use it in GitHub Desktop.

Select an option

Save solen003/681752c57f8bee735c2f451bab4786fd to your computer and use it in GitHub Desktop.
Write a program that accepts a sentence and calculate the number of letters and digits. Suppose the following input is supplied to the program: hello world! 123 Then, the output should be: LETTERS 10 DIGITS 3
phrase = input("Type in: ")
phrase = list(phrase)
l, d = 0, 0
for i in phrase:
if i.isalpha():
l = l + 1
if i.isdigit():
d = d + 1
else:
pass
print("Letters:", l)
print("Digits:", d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment