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)
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()
Comments
Leave a comment