Question: Before doing the exercise, make sure you have installed introcs package and imported it already. Here is a function that is not working properly due

Before doing the exercise, make sure you have installed introcs package and imported it already.

Here is a function that is not working properly due to the special precondition. Please use introcs.assert_equals() to test the result and indicate what is the problem of this function.

Use introcs.assert_equals() again to make sure the input qualifies the precondition and test your result again. (consider what n.find(' ') will return if the input is invalid)

"""

A module with a single, non-working function. The function in this module has a bug (in the sense that it does not satisfy its specification). This allows us to show off debugging. 

""" def last_name_first(n):

"""

Returns: copy of n but in the form 'last-name, first-name'

Parameter n: the person's name

Precondition: n is in the form 'first-name last-name' with one or more blanks between the two names no spaces in or

"""

 end_first = n.find(' ') 
 first = n[:end_first] 
 last = n[end_first+1:] 
 return last+', '+first 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!