Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 6: Write a python code that do the following: Ask the user for the numb

ID: 3848871 • Letter: E

Question

Exercise 6: Write a python code that do the following: Ask the user for the number of scores he/she 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 values to the screen: o The sum all the scores, o The min and the max scores, o 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)

Explanation / Answer

SCORES.py

n = int(input('Enter the no of scores '))
scores = list()
print('Enter the scores ')
for i in range(n):
   scores.append(int(input()))
print('The scores are : {}'.format(scores))
scores.sort()
print('sorted scores are : {}'.format(scores))
print('Sum of scores is : {}'.format(sum(scores))) # the sum() function sums up all the values in a list
print('Maximum score is : {}'.format(max(scores))) # the max() function returns the maximum value in a list
print('Minimum score is : {}'.format(min(scores))) # the min() function returns the minimum value in a list

# # Additions to the code
# search for an element

search = int(input('Enter the number to search or add : '))
if search in scores:
   print('Number is found at index scores[{}] '.format(scores.index(search)))
else:
   scores.append(search)
print('Modified list {}'.format(scores))

# replace an element

replace = input('Want to replace an element (Y or n): ')
if replace == 'Y' or replace == 'y':
   value_to_replace = int(input('Enter the element to replace: '))
   new_value = int(input('Enter the new value: '))
   scores[scores.index(value_to_replace)] = new_value
print('Modified list {}'.format(scores))

# Check if list is sort or not

for i in scores[:-1]:
   if scores[i+1] > scores[i]:
       sorted = True
   else:
       sorted = False
       break
scores.sort()
print('list is now sorted {}'.format(scores))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote