168k views
17 votes
Write a function longer_string() with two string input parameters that returns the string that has more characters in it. If the strings are the same size, return the string that occurs later according to the dictionary order. Use the function in a program that takes two string inputs, and outputs the string that is longer.

User EMazeika
by
5.3k points

1 Answer

2 votes

Answer:

Here you go :)

Step-by-step explanation:

Change this to your liking:

def longer_string(s1, s2):

if len(s1) > len(s2):

return s1

elif len(s1) < len(s2):

return s2

else:

return s2

x = input("Enter string 1: ")

y = input("Enter string 2: ")

print(longer_string(x, y))

User Ed Shee
by
5.5k points