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

Introduction

Write a Python program that accepts a string and calculate the number of digits and letters. 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

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

Leave a Comment