Advertisement
nanokatka

strings-task5

Feb 13th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. """
  2. 5. User enters a text string. You have to remove all “white symbols” and punctuation signs from it before further processing.
  3. Then, you need to print out each unique symbol and it’s quantity within an input string.
  4. DO NOT use collections for that.
  5.  
  6. Example:
  7. Enter string: Hello world!
  8.  
  9. Result:
  10.  
  11. E: 1
  12. n: 2
  13. t: 2
  14. e: 2
  15. r: 3
  16. s: 1
  17. i: 1
  18. g: 1
  19. H: 1
  20. l: 2
  21. o: 2
  22. w: 1
  23. d: 1
  24.  
  25. 5.1. Make this program case-insensitive.
  26.  
  27. """
  28. text=input("enter some text:")
  29.  
  30. text=text.replace('\t','')
  31. text=text.replace(' ','')
  32. text=text.replace(',','')
  33. text=text.replace('.','')
  34. text=text.replace(':','')
  35. text=text.replace(';','')
  36.  
  37. print("case sensitive case:")
  38. counter = [i+65 for i in range(122)]
  39. for i in counter:
  40. if chr(i) in text:
  41. print(chr(i), ":", text.count(chr(i)))
  42. else:
  43. pass
  44.  
  45. print("case insensitive case:")
  46. counter = [i+65 for i in range(26)]
  47. counter2=0
  48. for i in counter:
  49. if (chr(i) in text) or (chr(i+32) in text):
  50. counter2=text.count(chr(i))+text.count(chr(i+32))
  51. print(chr(i),"or ", chr(i+32),":", counter2)
  52. else:
  53. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement