Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using python 3. ALWAYS RATE MY ANSWERS A. Use the Python string method join to -

ID: 3888342 • Letter: U

Question

using python 3. ALWAYS RATE MY ANSWERS

A. Use the Python string method join to

- Create a new string that consists of lastName with a comma and a space followed by the firstName
firstName = “Sue”; lastName = “Jones”

- Create a phone number in the form ###-###-#### out of 3 strings

areaCode = “701”; prefix = “477”; lastPart=”2339”

B. Write a function called myFind which accepts a 2 strings as parameters (tmp and strToFind) and returns the location of the first occurrence of strToFind in tmp . You may NOT use Python’s built-in find OR rfind OR index functions

Explanation / Answer

A)

#save as file.py

firstName="Sue"
lastName="Jones"
#using join method to caoncatnate lastname
#with first name
name=", ".join([lastName,firstName])
print(name)


areaCode="701"
prefix="477"
lastPart="2339"
#using join method to caoncatnate area code
#with prefix and last part
phoneNumber="-".join([areaCode,prefix,lastPart])
print(phoneNumber)

Sample output

Jones, Sue
701-477-2339

-----------------------------------------------------------------------------------------------------------------------------

B)


def main():
      print(myFind("wikipedia","ki"))

#Method myFind that takes two string arguments
#retunrs the location of the second string
#in first string otherwise returns -1
def myFind(temp, strToFind):
    index = 0
    #check if strToFind in temp
    if strToFind in temp:
          #get starting letter
        c = strToFind[0]      
        for ch in temp:          
            if temp[index:index+len(strToFind)] == strToFind:
                  return index
            index =index+1
    return -1
#calling main method
main()

Sample output :

2