Q. Create a two dimensional List in Python that stores runs scored by a batsmen in five overs. The list looks somewhat like:
Runs = [[0, 6, 4, 1, 0, 0], [3, 0, 2, 0, 0, 0], [0, 0, 4, 4, 0, 1], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0]]
(a) Write a function that returns the over in which the batsman scored the highest runs.
(b) Write a function that returns the over(s) in which the batsman scored the minimum runs.
(c) Write a function that returns the total runs scored by the batsman.
Answer =
#a def maximum(Runs): sum_run = [ ] for i in Runs : sum_run.append( sum(i) ) return sum_run.index( max(sum_run) ) + 1 #b def minimum(Runs) : sum_run = [ ] for i in Runs : sum_run.append( sum(i) ) return sum_run.index( min(sum_run) ) + 1 #c def tot(Runs): sum_run = [ ] for i in Runs : sum_run.append( sum(i) ) return sum(sum_run) Runs = [[0, 6, 4, 1, 0, 0], [3, 0, 2, 0, 0, 0], [0, 0, 4, 4, 0, 1], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0]] print("Heighest run in", maximum(Runs), "over") print("Minimun run in", minimum(Runs), "over") print("Total runs :-", tot(Runs))
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )