There are 6 test cases and 5 are getting passed based on python 3 on a string operations problem, but 1 test case is failing since inception. Pls help me out. The question is as follows: 8 Strings are given in a function.
- Remove spaces from both end of strings: first, second, parent, city
- Capitalize : first, second, parent
- Print Strings with a space : first, second, parent, city
- Check if string : 'phone' only contains digits
- Check if phone number starts with value in string 'start' and print the result(True or False)
- Print : total no. of times 'strfind' appears in the strings : first, second, parent, city
- Print : list generated by using split function on 'string1'
- Find position of 'strfind' in 'city'
My Code is as follows: Let me know what wrong I have done. 5/6 test cases are passed only 1 test case failed for unknown reason. :(
def resume(first, second, parent, city, phone, start, strfind, string1):
first = first.strip()
second = second.strip()
parent = parent.strip()
city = city.strip()
first = first.capitalize()
second = second.capitalize()
parent = parent.capitalize()
print(first + " " + second + " " + parent + " " +city)
print(phone.isdigit())
print(phone[0]==start[0])
res = first + second + parent + city
res_count = res.count(strfind)
print(res_count)
print(string1.split())
print(city.find(strfind))
Not too sure without being given details on the test case. However, number 5 may be incorrect as you are only checking if the first values of the strings are the same. This is not the same as checking if "phone number starts with value in string 'start'". I recommend using the following code instead:
In addition number 6 seems like it could cause some mismatches with overlapping strings. Instead I would suggest using: