Q:

Write a Python program that accepts a string and calculate the number of digits and letters

0

Write a Python program that accepts a string and calculate the number of digits and letters

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used python 3.7 compiler for debugging purpose.

str = input("Input a string: ")
d=l=0
for c in str:
    if c.isdigit():
        d=d+1
    elif c.isalpha():
        l=l+1
    else:
        pass
print("Letters", l)
print("Digits", d)

Result:

Input a string: techstudy2018

Letters 9

Digits 4

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a Python program to check the validity of a ... >>
<< Write a Python program that prints all the numbers...