Here is a function that is supposed to return True if word (any string) ends with "s" and False otherwise: def ends_with_s(word): if len(word) < 1: return False return word[-1] == "s" Here is the test function I am using to test ends_with_s: def test_ends_with_s(): assert(ends_with_s("cats")) # option 1 assert(ends_with_s("") is False) # option 2 assert(ends_with_s("apple") is False) # option 3 assert(ends_with_s("S")) # option 4 Rewrite ends_with_s so that the test
Here is a function that is supposed to return True if word (any string) ends with "s" and False otherwise: def ends_with_s(word): if len(word) < 1: return False return word[-1] == "s" Here is the test function I am using to test ends_with_s: def test_ends_with_s(): assert(ends_with_s("cats")) # option 1 assert(ends_with_s("") is False) # option 2 assert(ends_with_s("apple") is False) # option 3 assert(ends_with_s("S")) # option 4 Rewrite ends_with_s so that the test
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
Related questions
Question
Here is a function that is supposed to return True if word (any string) ends with "s" and False otherwise:
def ends_with_s(word):
if len(word) < 1:
return False
return word[-1] == "s"
if len(word) < 1:
return False
return word[-1] == "s"
Here is the test function I am using to test ends_with_s:
def test_ends_with_s():
assert(ends_with_s("cats")) # option 1
assert(ends_with_s("") is False) # option 2
assert(ends_with_s("apple") is False) # option 3
assert(ends_with_s("S")) # option 4
assert(ends_with_s("cats")) # option 1
assert(ends_with_s("") is False) # option 2
assert(ends_with_s("apple") is False) # option 3
assert(ends_with_s("S")) # option 4
Rewrite ends_with_s so that the test passes
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT