Skip to content

Instantly share code, notes, and snippets.

@HHGGHHGG
Created April 6, 2017 17:51
Functions
name = "Jack"
gpaList = [3.5,4,3.94,4,4,4,4]
def gpa(name, gpaList):
sumgpa = 0
for i in range(len(gpaList)):
sumgpa = sumgpa+float(gpaList[i])
print "%s's overall average GPA is %s" % (name ,str(sumgpa/len(gpaList)))
def gpaK(name, gpaList, k):
if k>0 and k<=len(gpaList):
sumgpa = 0
for i in range(len(gpaList)- k, len(gpaList)):
sumgpa = sumgpa+float(gpaList[i])
print "%s's overall average GPA is " % name + str(sumgpa/k)
else:
print "Please input k in range of your list's length."
gpa(name,gpaList)
gpaK(name, gpaList, 4)
print "Please insert your name."
name = raw_input()
print "%s, please input the number of semesters you have taken." % name
def gpa(number):
gpaList = []
for i in range(int(number)):
gpaList.append(raw_input("Enter the GPA for semester " + str(i+1) + ": " ))
cumgpa = 0
for i in range(len(gpaList)):
cumgpa = cumgpa+float(gpaList[i])
print "Dear %s, your cumulative GPA is " % name + str(cumgpa/int(number))
number = raw_input()
gpa(number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment