In a class test teacher announces the marks (negative marking allowed) of n students a student can achieve max 100 marks. Write a python function p-marks(*marks) that takes no. 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 re-sort(*marks) which returns the students marks as a comma-separated string with elements in ascending order ( You can use built-in function max() or min() to do this) . Specify input in fixed form.
#for printing marks
def print_marks(*marks):
for m in marks:
if m > 100:
print('Invalid mark:', m)
exit()
s = rec_Sort(*marks)
print(s)
#for sorting marks
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)
#for printing the last answer
def main():
print_marks(10, 93, 45, 76, 87, 45)
main()
Comments
Leave a comment