Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Make a program that:
- 1. counts the number of occurrence of a character (regardless of its case) from a given string:
- Example Input/Output1:
- Input any string: thE five boxing wIzards jump quIckly.
- Character to check: i
- Number of occurrence for i: 4
- Example Input/Output2:
- Input any string: thE five boxing wIzards jump quIckly.
- Character to check: e
- Number of occurence for e: 2
- 2. gets the sum of all the numbers (positive numbers only) found from a given string:
- Example Input/Output1:
- Input any string: th3 f1v3 b0x1n-6 w1z4rd5 jump qu-1ckly.
- Sum of all digits from the string: 25
- Example Input/Output2:
- Input any string: C#3ck 4ll d d1g1ts fr0m th15 57r1n6 @nd 637 d 5um d0n3!
- Sum of all digits from the string: 58
- Example Input/Output3:
- Input any string: 7-4-1982
- Sum of all digits from the string: 31
- 3. inputs a string and converts the string in Title Case.
- Example Input/Output:
- Input any string: the quick brown fox jumps over the lazy dog.
- String in title case: The Quick Brown Fox Jumps Over The Lazy Dog.
- 4. inputs a string and converts the string in reverse titlE casE.
- Example Input/Output:
- Input any string: the five boxing wizards jump quickly
- String in title case: thE fivE boxinG wizardS jumP quickly
- 5. finds and replaces a character (regardless of its case) from a given string.
- Example Input/Output:
- Input any string: Programming is so boring.
- Find character: o
- Replace with: x
- Result after replacing o with x: Prxgramming is sx bxring.
- 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.
- Example Input/Output:
- Number of elements to check: 6
- String1: aa
- String2: xyx
- String3: sleep eat love
- String4: Eddie Vedder’s collections are extremely rare
- String5: first 2nd 3rd 4th
- String6: abc xyz cbA
- Found 3 string(s) having the same character on both ends.
- ============================
- #FOR QUESTION NUMBER 1
- inp = input('Input any string: ')
- char = input('Character to check: ')
- print ('Number of occurence for',char,':',inp.count(char))
- #FOR QUESTION NUMBER 2
- zxy = input('Input any string: ')
- counter=0
- for zz in zxy:
- if zz.isdigit():
- counter += int(zz)
- print(counter)
- #FOR QUESTION NUMBER 3
- inp1 = input('Input any string: ')
- title = inp1.title()
- print (title)
- #FOR QUESTION NUMBER 4
- inp2 = input('Input any string: ')
- a = inp2[::-1]
- b = a.title()
- c = b[::-1]
- print(c)
- #FOR QUESTION NUMBER 5
- in3 = input('Input any string: ')
- y = input('Find Character: ')
- z = input('Replace with: ')
- x = in3.replace(y,z)
- print(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement