+ 1
# write a program to read the scores of n players and display total score,min score # max score(max,min score expltn needed)
n=int(input("Enter how many players?")) # 5 scores=[] for i in range(n): # 0 1 2 3 4 score=int(input("Enter score")) scores.append(score) print(f'Scores are {scores}') total=0 for s in scores: total=total+s print(f'Total score is {total}') maxscore=0 minscore=0 for s in scores: if s>maxscore: maxscore=s print(f'maximum score {maxscore}') for i in range(n): # 0 1 2 3 4 if i==0: minscore=scores[0] elif scores[i]<minscore: minscore=scores[i] print(f'minimum score {minscore}')
7 Answers
+ 1
Check in your code, from
for i in range(5) :
print(i, scores[i] )
# i used for index
# scores[I] represents values
+ 1
I need minimum score explaination can any one
+ 1
First it set minscore = scores[0]
And any other value are tested minscore<scores[I] , if yes then update minscore[I]
Else continue
Ex:: 3 4 5 2 7
Min=3
for i in range(5) :
I = 0 => setting min=3
Next
I= 1 => 4<3 false
I= 2 => 5<3 false
I= 3 => 2<3 true so set min=2
I= 4 => 7<2 false
So min=2
May you have doubt, why not min=0 at initially, if yes then for all inputs expect for negative values min<scores[0] is false so minscore value remain 0 after loop. But input have no value 0.
hope it helps..
+ 1
It's more helpful brotherâ¤ď¸â¤ď¸
+ 1
I understood everything,in my solution, in if statment why I==0, is it index or just considered score. As zero initial,little confused
+ 1
TQ you for helping
0
Okkk got itâ¤ď¸â¤ď¸â¤ď¸â¤ď¸â¤ď¸