65.5k views
3 votes
Write a function min that has two str parameters and returns the smallest. (Smallest in the sense of coming first alphabetically, not in the sense of "shortest".)

1 Answer

1 vote

Answer:

The function written in python is as follows

def min(str1,str2):

if str1 < str2:

return str1

else:

return str2

Explanation:

This line defines the function min, along with two parameters str1 and str2

def min(str1,str2):

This line checks if str1 is less than str2

if str1 < str2:

If yes, the function returns str1

return str1

If otherwise,

else:

The function returns str2

return str2

Take for instance

str1 = "abc"

str2 = "cba"

The function will return str1 because str1 is less than str2 in the sense that the first letter of str1 (a) is less than the first letter of str2 (c)

User TroySteven
by
7.7k points