Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

function - Make a Program in Python that calculates the student's GPA?

I am in need of assistance on a coding question in Python.

I have to calculate a student’s GPA. The program must ask them how many classes they are taking, then ask them to enter the grades for each class and if it is weighted.

The program should then output the averaged GPA including the decimal place, and my main program must call the function.

The question gives a chart for the non-weighted and weighted number scores that correlates with the given letter grade: gpa chart

Here's what I have so far:

def average (c): 
    div = c
    avg =(1.0*(sum(scores))/div)

#****************MAIN********************
c = input("How many classes are you taking?")
print ("You are taking " + str(c) + " classes.") 
x = input("Enter your letter grade.") 
w = int(input("Is it weighted? (1 = yes)")
    while (c <= 7): #Here it is saying that there is a syntax error because I input a while loop. I don't know why it is saying this. 
    if (x == A): 
        if (w == 1): 
            print ("Your GPA score is 5")
        else: 
            print ("Your GPA score is 4")
    elif (x == B): 
        if (w == 1): 
            print ("Your GPA score is 4")
        else: 
            print ("Your GPA score is 3") 

    elif (x == C): 
        if (w == 1): 
            print ("Your GPA score is 3")
        else: 
            print ("Your GPA score is 2") 

    elif (x == D): 
        if (w == 1): 
            print ("Your GPA score is 2") 
        else: 
            print ("Your GPA score is 1") 

    elif (x == F): 
        if ( w == 1): 
            print ("Your GPA score is 1")      
        else: 
            print ("Your GPA score is 0") 

    scores = []
    list.append(x)

    average(c)

Any help would be much appreciated! :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Not sure about what you are asking for, but fixing just after the function definitions might be a good start

Don't

def classes(c): 
print ("You are taking " + c  + " classes.") 

Do

def classes(c): 
    print ("You are taking " + c  + " classes.") 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...