File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ # Write a program that accepts a sentence and calculate the number of
2+ # letters and digits. Suppose the following input is supplied to the
3+ # program:
4+ # hello world! 123
5+ # Then, the output should be:
6+ # LETTERS 10
7+ # DIGITS 3
8+
9+ # using variables
10+ s = input ("Enter input: " )
11+ countNumber = 0
12+ countLetter = 0
13+ for i in s :
14+ if i .isdigit () :
15+ countNumber = countNumber + 1
16+ elif i .isalpha ():
17+ countLetter = countLetter + 1
18+ print ('LETTERS' , countLetter )
19+ print ('DIGITS' , countNumber )
20+
21+ # using dictionary
22+ # s = input()
23+ # d={"DIGITS":0, "LETTERS":0}
24+ # for c in s:
25+ # if c.isdigit():
26+ # d["DIGITS"]+=1
27+ # elif c.isalpha():
28+ # d["LETTERS"]+=1
29+ # else:
30+ # pass
31+ # print ("LETTERS", d["LETTERS"])
32+ # print ("DIGITS", d["DIGITS"])
You can’t perform that action at this time.
0 commit comments