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
"""
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started