Answer to Question #293984 in Python for Michael

Question #293984

 In a class test the teacher announces the marks (negative marking is allowed) of n (n>0) students. A student can achieve maximum 100 marks. Write a python function print_marks(*marks)  that takes number of students, marks of students and return the marks and check the marks are valid or not. If valid then it calls the recursive function rec_Sort(*marks) which returns the students marks as a comma-separated string with elements in ascending order. (You can use of built-in function max ()/min() to do this)



1
Expert's answer
2022-02-04T10:33:38-0500
def print_marks(*marks):
    for m in marks:
        if m > 100:
            print('Invalid mark:', m)
            exit()
    s = rec_Sort(*marks)
    print(s)


def rec_Sort(*marks):
    if len(marks) == 1:
        return str(marks[0])
    
    m = min(marks)
    res = list(marks)
    res.remove(m)
    return str(m) + ", " + rec_Sort(*res)


def main():
    print_marks(10, 93, 45, 76, 87, 45)


main()

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