Programming Languages
Write an ML function call ch. This function takes a tuple of length 4 and returns “yes” if the second element is greater than the first; otherwise, it returns "no". The function need not behave properly if there are less than or more than 4 elements;
$ ch (4,5,6,7);
no
$ ch (7,9,8,4);
yes
Here is the answer..
CODE:
def ch(*t):
if(len(t)==4):
second =t[1]
for number in t:
if second < number: #if second element less than any other
elements in tuple
return "no"
return "yes" #if second element greater than all numbers in
tuple
else:
return "please enter four elements"
print(ch(4,5,6,7))
print(ch(7,9,8,4))
OUTPUT:
If you have any doubts please COMMENT...
If you need any modifications please COMMENT...
If you understand the answer please give THUMBS UP...
Get Answers For Free
Most questions answered within 1 hours.