Skip to content

Commit 550144f

Browse files
committed
q13.py
1 parent f0217ee commit 550144f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

q13.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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"])

0 commit comments

Comments
 (0)