-3

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.

  1. Remove spaces from both end of strings: first, second, parent, city
  2. Capitalize : first, second, parent
  3. Print Strings with a space : first, second, parent, city
  4. Check if string : 'phone' only contains digits
  5. Check if phone number starts with value in string 'start' and print the result(True or False)
  6. Print : total no. of times 'strfind' appears in the strings : first, second, parent, city
  7. Print : list generated by using split function on 'string1'
  8. 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))
Thomas Sablik
  • 16,127
  • 7
  • 34
  • 62
Ajith Kan
  • 1
  • 1
  • 3
  • Do you know what the failing test case is? Did you try running the code with that test input locally? What happens when you do? What is supposed to happen instead? – Karl Knechtel Mar 24 '21 at 18:25
  • Note that, according to its documentation, `isdigit` returns whether or not a string is a "digit string", where "A string is a digit string if all characters in the string are digits and there is at least one character in the string." Not sure if that matches what #4 is asking. – Scott Hunter Mar 24 '21 at 18:30
  • `phone[0]==start[0]` means `phone` and `start` have the same first character, *not* that `phone` starts with what is in `start`. Suppose `phone` was `'123'` and `start` was `'14'`. – Scott Hunter Mar 24 '21 at 18:33
  • If `first='str'` and `second='find'`, what should the answer to #6 be? – Scott Hunter Mar 24 '21 at 18:35
  • This worked :) print(phone.startswith(start)) – Ajith Kan Apr 12 '21 at 17:59

2 Answers2

0

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:

print(phone.startswith(start))

In addition number 6 seems like it could cause some mismatches with overlapping strings. Instead I would suggest using:

print(first.count(strfind) + second.count(strfind) + parent.count(strfind) + city.count(strfind))
thornejosh
  • 148
  • 8
0
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.isnumeric())
print(phone.startswith(start))
res = first + second + parent + city
res_count = res.count(strfind)
print(res_count)
print(string1.split())
print(city.find(strfind))
Yuvraj
  • 1