I'm new to python so any help would be appreciated, here is a code i've been working on for calculating gpa, I have to calculate gpa of an inputed number of courses by a user (could be 2-infinte number of courses); btw this is not the whole function but only the part i'm having trouble with, the other part (not shown here) is for g (gradepoint) which changes for example A to 4 but I know how to do it. The inputed number of courses have to be included in a string, for ex;
Enter number of courses:
Enter course 1's mark(in letters like A+):
Enter course 1's weight:
Enter course 2's mark:
....
Enter course 6's mark:
Thank you, btw we are not allowed to use lists, dictionaries, or anything that might be advanced

Code starts here
numbercourses = float(input("Enter number of courses: "))

def calculate_gpa(numbercourses):
coursenumber = 1

while numbercourses > 0:
coursenumber = coursenumber + 1
numbercourses = numbercourses - 1
g = float(input("Enter grade course No. ", coursenumber))
weight = float(input("Enter  weight course No. ", coursenumber))
gpa = gpa + round((conversion(g)/weight),2)
return

Your usage says it takes grades and weights in order, your snippet would do something completely different, if we fix the indention problem first.

I'm also a Python-starter. Question to the OP: What is the purpose of following function?

def calculate_gpa(numbercourses):
coursenumber = 1

It returns nothing; None I guess.
It does nothing with the parameter numbercourses.
It sets a variable(global?) coursenumber to 1.

'm also a Python-starter. Question to the OP: What is the purpose of following function?

def calculate_gpa(numbercourses):
coursenumber = 1

It returns nothing; None I guess.
It does nothing with the parameter numbercourses.
It sets a variable(global?) coursenumber to 1.

Yes it returns None. If a function does not have a return value, then it returns None.

It does not set the coursenumber global variable. It defines a new one in the function. Global variable can only be set by issuing a global statement.

commented: Starters can always use some good explanation!Thanks. +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.