Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters


Introduction

Write a Python function that accepts a string and calculate the number of upper case letters and lower case 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. def string_test(str):
  2. d={"UPPER_CASE":0, "LOWER_CASE":0}
  3. for c in str:
  4. if c.isupper():
  5. d["UPPER_CASE"]+=1
  6. elif c.islower():
  7. d["LOWER_CASE"]+=1
  8. else:
  9. pass
  10. print ("Original String : ", str)
  11. print ("No. of Upper case characters : ", d["UPPER_CASE"])
  12. print ("No. of Lower case Characters : ", d["LOWER_CASE"])
  13.  
  14. string_test('TechStudy - The Complete Debugging Solution')

Result

python language techstudy.org

     





Related Topics




Popular Posts