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:
Input a string: techstudy2018
Letters 9
Digits 4
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
I have used python 3.7 compiler for debugging purpose.
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