




Problem 1 - Sorting a List
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 both 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 empty and keep printing the number that is returned.
https://www.liveexamhelper.com/


for i in range(len(L)): if L[i] > maximum: maximum = L[i] index = i del L[index] return maximum # this is fine: while len(L) > 0: for i in range(10): print find_largest(L), https://www.liveexamhelper.com/

Problem 2 – Report card with GPA Write a program where the user can enter each of his grades, after which the program prints out a report card with GPA. Remember to ask the user how many classes he took. Example output is below. How many classes did you take? 4 What was the name of this class? English What was your grade? 94 ... REPORT CARD: English - 94 Math – 96 Science – 91 Social Studies - 88 Overall GPA – 92.25 https://www.liveexamhelper.com/


running_sum = running_sum + grade return float(running_sum) / len(grades) # remember we want decimals, so # use float(...) # Main program code class_names = [] class_grades = [] number_classes = int(raw_input("How many classes did you take? ")) print # this prints a blank line # Now we're going to ask the same two questions over and over --> loop! # Since we know how many times we're looping (number_classes), we use for. # Note that we need a variable name for the "for", but we don't use it here. # What does range return? A list of numbers, from 0 to number_classes. for arbitrary_variable_name in range(number_classes): name = raw_input("What is the name of this class? ") grade = int(raw_input("What grade did you get? ")) https://www.liveexamhelper.com/

class_names.append(name) # add the two things to our lists... class_grades.append(grade) print # blank line # Now we'll print the report card. The report card should look like: # class name - grade # Over and over again --> loop! How many of these lines? number_classes print "Report card:" print for class_number in range(number_classes): print class_names[class_number], "-", class_grades[class_number] print print "Term GPA:", calculate_gpa(class_grades) https://www.liveexamhelper.com/
