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).
Example-1
Example-2
Example-3
Example-4
Example-5
Input:
5
6
56
58
Output:
5, 6, 56, 58
Input:
12
-3
45
37
90
Output:
-3, 0, 12, 37, 45, 90
Input:
56
96
100
101
Output:
Invalid Input
Input:
56
196
20
10
Output:
Invalid Input
Input:
50
40
10
Output:
0, 10, 40, 50
def print_marks(*marks):
nums = []
for mark in marks:
if type(mark) == int and mark >= -100 and mark <= 100:
nums.append(int(mark))
else:
print('Invalid Input')
return None
print(rec_sort(nums))
def rec_sort(nums):
if len(nums) == 1:
return nums[0]
else:
minNum = min(nums)
nums.remove(minNum)
return f"{minNum}, {rec_sort(nums)}"
print_marks(12, -3, 45, 0, 90, 37)
Comments
Leave a comment