Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.62 KB | None | 0 0
  1. Make a program that:
  2.  
  3. 1. counts the number of occurrence of a character (regardless of its case) from a given string:
  4.  
  5. Example Input/Output1:
  6. Input any string: thE five boxing wIzards jump quIckly.
  7. Character to check: i
  8. Number of occurrence for i: 4
  9.  
  10. Example Input/Output2:
  11. Input any string: thE five boxing wIzards jump quIckly.
  12. Character to check: e
  13. Number of occurence for e: 2
  14.  
  15. 2. gets the sum of all the numbers (positive numbers only) found from a given string:
  16.  
  17. Example Input/Output1:
  18. Input any string: th3 f1v3 b0x1n-6 w1z4rd5 jump qu-1ckly.
  19. Sum of all digits from the string: 25
  20.  
  21. Example Input/Output2:
  22. Input any string: C#3ck 4ll d d1g1ts fr0m th15 57r1n6 @nd 637 d 5um d0n3!
  23. Sum of all digits from the string: 58
  24.  
  25. Example Input/Output3:
  26. Input any string: 7-4-1982
  27. Sum of all digits from the string: 31
  28.  
  29. 3. inputs a string and converts the string in Title Case.
  30.  
  31. Example Input/Output:
  32. Input any string: the quick brown fox jumps over the lazy dog.
  33. String in title case: The Quick Brown Fox Jumps Over The Lazy Dog.
  34.  
  35. 4. inputs a string and converts the string in reverse titlE casE.
  36.  
  37. Example Input/Output:
  38. Input any string: the five boxing wizards jump quickly
  39. String in title case: thE fivE boxinG wizardS jumP quickly
  40.  
  41. 5. finds and replaces a character (regardless of its case) from a given string.
  42.  
  43. Example Input/Output:
  44. Input any string: Programming is so boring.
  45. Find character: o
  46. Replace with: x
  47.  
  48. Result after replacing o with x: Prxgramming is sx bxring.
  49.  
  50. 6. inputs a series of strings and counts the number of strings where the string length is 3 or more and has the same  character (regardless of its case) on both ends.
  51.  
  52. Example Input/Output:
  53. Number of elements to check: 6
  54. String1: aa
  55. String2: xyx
  56. String3: sleep eat love
  57. String4: Eddie Vedder’s collections are extremely rare
  58. String5: first 2nd 3rd 4th
  59. String6: abc xyz cbA
  60.  
  61. Found 3 string(s) having the same character on both ends.
  62.  
  63. ============================
  64.  
  65. #FOR QUESTION NUMBER 1
  66. inp = input('Input any string: ')
  67. char = input('Character to check: ')
  68.  
  69. print ('Number of occurence for',char,':',inp.count(char))
  70.  
  71. #FOR QUESTION NUMBER 2
  72. zxy = input('Input any string: ')
  73. counter=0
  74. for zz in zxy:
  75.     if zz.isdigit():
  76.         counter += int(zz)
  77. print(counter)
  78.        
  79.  
  80. #FOR QUESTION NUMBER 3
  81. inp1 = input('Input any string: ')
  82. title = inp1.title()
  83. print (title)
  84.  
  85. #FOR QUESTION NUMBER 4
  86. inp2 = input('Input any string: ')
  87. a = inp2[::-1]
  88. b = a.title()
  89. c = b[::-1]
  90. print(c)
  91.  
  92. #FOR QUESTION NUMBER 5
  93. in3 = input('Input any string: ')
  94. y = input('Find Character: ')
  95. z = input('Replace with: ')
  96. x = in3.replace(y,z)
  97. print(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement