Python - String Operations 2
Rajesh is trying to write a program that will evaluate and correct his resume.
Define a function called 'resume' which takes eight parameters. All the parameters are string.
- The first parameter first is the first time.
- the second parameter second is the second time
- the third parameter parent is the name of the father or mother
- the fourth parameter city is the name of the city
- the fifth parameter contains phone number in the format of string
- the sixth and seventh parameter contains a single string
- the eighth parameter contains a sentence
The function definition code stub is given in the editor. Do the following steps in sequence and generate print statements based on conditions given below.
1. Remove the spaces from both the end for the string: First, second, parent, city
2. Capitalize the first letter for the stings: first, second, parent
3. Print the strings first, second, parent and city separated by space.
4. Check if the string phone contains only numerical characters and print the result (True of False)
5. Check if the phone number starts with the value in string string start and print the result(True or False)
6. Print Total number of times the string strfind appears in the strings(first, second, parent, city)
7. Print the list generated by using the split function on string(Hint: Use split() function)
8. Find the position of string string strfind in the city. (Hint: Use find() function)
Constraints
- Every input is String.
Sample Case 0
Sample Input
STDIN Function ----- -------- firstname → first lastname → second father → parent city → city 9874563214 → phone 9 → start y → strfind any sentence goes here → string1Sample Output
Firstname Lastname Father city
True
True
1
['any', 'sentence', 'goes', 'here']
3
Answer:
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'resume' function below.
#
# The function is expected to print a STRING.
# The function accepts following parameters:
# 1. STRING first
# 2. STRING second
# 3. STRING parent
# 4. STRING city
# 5. STRING phone
# 6. STRING start
# 7. STRING strfind
# 8. STRING string1
#
def resume(first, second, parent, city, phone, start, strfind, string1):
# Write your code here
print(first.strip().capitalize(),second.strip().capitalize(),
parent.strip().capitalize(),city.strip())
print(phone.isnumeric())
print(phone.startswith(start))
tot=first+second+parent+city
print(tot.count(strfind))
print(string1.split())
print(city.find(strfind))
if __name__ == '__main__':
a = input()
b = input()
c = input()
d = input()
ph = input()
no = input()
ch = input()
str = input()
resume(a, b, c, d, ph, no, ch, str)
Click on image to get extra information:
No comments:
Post a Comment
If you have any doubts, Please let us know.