Created
July 15, 2018 21:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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