Skip to main content

Hands-on - String Operations Part 2

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 name.
  • the second parameter second is the second name
  • 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 eigth parameter contains string sentence.

 

The function definition code stub is given in the editor. Generate print statements  based on conditions given below:

 

  • Remove the spaces from both the end for the strings (first, second, parent, city)
  • Capitalize the first word for the strings (first, second, parent)
  • print the strings first, second, parent and d separated by space.
  • check if the string phone contains only numerical characters and print the result
  • check if the string phone starts with string start and print the result
  • print number of times the string strfind appears in the strings (first, second, parent, city)
  • split the string string1 using split function and print the result
  • use the find method to find the position of string strfind in city

 

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 →  string1

 

Sample Output

Firstname Lastname Father city
True
True
1
['any', 'sentence', 'goes', 'here']
3

 

 



#!/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
    first = first.strip()
    first = first.capitalize()
    second = second.strip()
    second = second.capitalize()
    parent = parent.strip()
    parent = parent.capitalize()
    print(first,second,parent,city.strip())
    print(phone.isnumeric())
    print(phone.startswith(start))
    a = first+second+parent+city
    print(a.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) 

Comments

Popular posts from this blog

Python Hacker Rank Question and Answer -- Hands-on - Range

Python - Range1   Define a function called ` rangefunction ` which takes three parameters . The first parameter is ` startvalue ` , the next parameter is ` endvalue` and the last parameter is 'stepvalue' .   The function definition code stub is given in the editor. Generate the squares of numbers from ` startvalue ` to ` endvalue ` using range   based on condition given below:   Print the values which must be separated by tab spaces. Note: startvalue and endvalue both are inclusive in the range.    Constraints 1 ≤ startvalue Input Format for Custom Testing   In the first line  startvalue given In the second line endvalue given In the second line stepvalue given     Sample Case 0   Sample Input STDIN      Function -----      -------- 2       → startvalue = 2 9 → endvalue = 9 2 → ...

Python Hacker Rank Question and Answer -- Hands-on - Namespaces

  Python - Namespaces Write the function definition for the function  ' Assign ' to assign the different types of variables in its parameters to new variables. Parameters: 1.An INTEGER in the variable ' i ' 2.A FLOAT in the variable ' f ' 3.A STRING in the variable ' s ' 4.A BOOLEAN in the variable ' b '   New Variables to be assigned with : 1.An INTEGER in the variable ' w ' 2.A FLOAT in the variable ' x ' 3.A STRING in the variable ' y ' 4.A BOOLEAN in the variable ' z '   Assign the parameter variables  Respectively . and Print these in the following order: 1.w 2.x 3.y 4.z 5.Display all the objects defined in the current namespace by using the 'dir' function   Input Format for Custom Testing: # In the first line, value for ' i ' # In the second line, value for ' f ' # In the third line, value for ' s ' # In the fourth line, value for ' b '   Sample Test Case 1:   Sampl...

Python Hacker Rank question and answer --HandsOn -- Print

Greeting Quote Mr.Greet is the name of the digital notice board placed at the entrance of the seminar hall.Its purpose is to welcome each and every participants of the seminar by showing a welcoming quote with their name on it. It is based on the function ‘ Greet ’ which takes a single parameter ‘ Name ’ as a String are the names of the participants as Input One by one. Write the function definition for ‘ Greet ’ which will generate the welcoming quote as below : For Example,the ‘ Name ’ is “Ramakrishnan” then the welcoming quote will be : Output: Welcome Ramakrishnan. It is our pleasure inviting you. Have a wonderful day.   Note: ‘ Name ’ must be of String Data type.   Input Format for Custom Testing: It’s a single line contains a name. Sample Test Case 1:   Sample Input STDIN      Function -----      -------- Karthik → Name Sample Output Welcome Karthik. It is our pleasure inviting yo...