Answer to Question #240488 in Python for Isabel Cortez

Question #240488

Activity #5 – Applying Functions


The output of this activity will be the same as activity #3 but instead you are

required to use a function for the following algorithm:


1. A function for getting the length of each string

2. A function to get the shortest string

3. And a function to get the longest string

Assume that each string has its own unique length.


Sample Run:


Sample Run A

Enter value of X: 3

Enter string value: a

Enter string value: ab

Enter string value: abc

a - total length is 1

ab - total length is 2

abc - total length is 3

The shortest string is 1

The longest string is 3


Sample Run B

Enter value of X: 4

Enter string value: chico

Enter string value: strawberry

Enter string value: banana

Enter string value: guyabano

chico - total length is 5

strawberry - total length is 10

banana - total length is 6

guyabano - total length is 8

The shortest string is chico

The longest string is strawberry


1
Expert's answer
2021-09-22T23:49:35-0400
x=int(input("Enter value of X: "))
num=[]
for n in range(x):
    N=input("Enter strng value: ")
    num.append(N)



r=len(num[0])
y=len(num[1])
z=len(num[2])
print("Length of ",num[0],"is",r)
print("Length of ",num[1],"is",y)
print("Length of ",num[2],"is",z)


def min(x,y,z):
    if (x < y) and (x < z):
       min = x
    elif (y < x) and (y < z):
        min = y
    elif (z < y) and (z < x):
        min = z
    return(min)


def max(x,y,z):
    if (x > y) and (x > z):
       max = x
    elif (y > x) and (y > z):
        max = y
    elif (z > y) and (z > x):
        max = z
    return(max)


#shortest strng
print("Shortest strng is", min(r,y,z))


#longest
print("Shortest strng is", max(r,y,z))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS