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.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. str = input("Input a string: ")
  2. d=l=0
  3. for c in str:
  4. if c.isdigit():
  5. d=d+1
  6. elif c.isalpha():
  7. l=l+1
  8. else:
  9. pass
  10. print("Letters", l)
  11. print("Digits", d)

Result

python language techstudy.org

     





Related Topics




Popular Posts