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

Code in Python: Write a program that asks the user to enter 10 (positive) number

ID: 3734564 • Letter: C

Question

Code in Python:

Write a program that asks the user to enter 10 (positive) numbers. The program should then print the numbers in sorted order, from biggest to smallest. To do this, first write a function that takes a list and finds the largest element. It then 1) deletes that element from the list and 2) returns that element. Hint: You will need to store two variables in this function: the biggest number you've seen so far (remember to initially set this to 0), and its position. Then iterate over the list, and for each element, check if it's bigger than the biggest number you've seen so far. If it is, change botlh variables (remember to change BOTH)! So, in your main program, you'll have to keep calling this function (in a loop) until the list is emm

Explanation / Answer

In the following program, please read the comments carefully, to understand the execution.

Hope this helps! If it works please thumbs up!

#================================================

# Function Initialization
def sort(num):
     mx=max(num);        # Finding the maximum in the list and storing it
     num.remove(mx);     # Removing the maximum from the list
     return(mx);         # Returning the stored maximum number from the list

############# MAIN PROGRAM ##############        
num=[];

# Taking the input
for i in range(1,11):
     num.append(int(input('Please enter a positive number: ')));

# Looping over the list till after mulitple removals the it goes empty
while(len(num)>0):
     print(sort(num));   # Calling the sort function and printing the maximum returned number

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