Write a python code that do the following Ask the user for t

Write a python code that do the following: Ask the user for the number of scores he/sbe will be entering. Create a list to hold the scores. Print all the scores to the screen. Sort all the scores for the user and print the sorted list to the screen. Print the following yalues to the screen: o The suman the scores, of The min and the max scores lo The average Add to your python code the following functions Look for a given number and return its position if the number is in the list otherwise add this number to the list. Ask the user if he wants to replace any values in the list. If he does, then get the value to find and the replacement value. Check the list is sort or not. Hint define variable with name sorted and set its initial value to False Check the list if it is sorted, then set the value of this variable to True)

Solution

# Program starts here.

#scoresList is list to hold numbers
scoresList = list()

nb = int(input(\'Enter the number of scores: \'))

# get all the scores from the user.
while(nb > 0):
   score = int(input(\'Enter the score: \'))
  
   # Check if the score is already in the list.
   # if yes, do not append.
   if score in scoresList:
       tmp = scoresList.index(score)
       print \"This score is already in list. The corresponding index is: \" + str(tmp)
   else:
       scoresList.append(score)
       nb = nb - 1;  
  
# sort the list.
scoresList.sort()

print \"The scores in the sorted list are: \"
print scoresList

# find min, max, sum and average
minElement = min(scoresList)
maxElement = max(scoresList)
listSum = sum(scoresList)
listAverage = listSum/len(scoresList)

print \"Max element in the list: \" + str(maxElement)
print \"Min element in the list: \" + str(minElement)
print \"Sum of all elements in the list: \" + str(listSum)
print \"Average of all elements in the list: \" + str(listAverage)

replaceNumber = input(\'Do you want to replace any values in list? (y for yes OR n for no) \')

if replaceNumber == \'y\':
   oldvalue = int(input(\'Enter the value to replace: \'))
   newvalue = int(input(\'Enter the new value: \'))
   tmp = scoresList.index(oldvalue)
   scoresList.insert(tmp,newvalue)

 Write a python code that do the following: Ask the user for the number of scores he/sbe will be entering. Create a list to hold the scores. Print all the score

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site