# -*- coding: utf-8 -*- """ Created on Fri Sep 16 11:08:44 2022 @author: cpresser """ grades = [70, 75, 90, 86, 93, 72] print(grades) #delete del grades[2] print(grades) #another delete grades.pop(2) #remove an item at an index print(grades) #remove a value grades.remove(70) #removing a specified value print(grades) grades.append(75) print(grades) grades.remove(75) #remove the first 75 print(grades) #a string className = "Scientific Computing" print(className[0]) #Can't assign an item in a string # className[0] = "T" print(className[0]) grades = grades + [97, 83, 79, 91] print(grades) print(f"There are {len(grades)} grades in the list.") #average the grades n = 0 sum = 0 while n < len(grades): #7 sum = sum + grades[n] #step n = n + 1 avg = sum/len(grades) print(f"The average is {avg:.4}.") print(f"The average is {avg:.4f}.") #for loops #print the values # for each value, g, in grades for g in grades: #print the value print(g) #calculate the average using a for loop sum = 0 for g in grades: #put the next grade into variable g sum = sum + g avg = sum/len(grades) print(f"The average is {avg:.4}.") #reverse the list grades.reverse() print(grades) #sort the list of grades. grades.sort() print(grades) #loop through the characters in a string for c in "Hello": print(c)