Python Simple program

Roy Smith roy at panix.com
Sat Jan 18 14:07:16 EST 2014


In article <60955b74-7bc8-4c72-94e1-849015985034 at googlegroups.com>,
 indar kumar <indarkumar59 at gmail.com> wrote:

> On Saturday, January 18, 2014 11:00:47 AM UTC-7, indar kumar wrote:
> > Hello, I am a newbie. Can somebody help me write the code for following 
> > program?
> > 
> > 
> > 
> > 
> > 
> > Write a program that takes student grades and prints out the GPA. The 
> > information is input, one student per line in the format: <student id> 
> > <course1 grade> <course2 grade> ...
> > 
> > The number of students is not known in advance. You should prompt the user 
> > for more until they enter an empty line. The number of courses per student 
> > varies and is also not known in advance. You should read as many grades as 
> > are entered on the line.
> 
> 
> 
> Hello, I think I just need one loop not separate loops. One while loop should 
> be enough. 

If you're going to accept multiple lines of input (one line per 
student), and multiple grades on each line, you're going to need two 
loops.  One loop iterates over the students, the other loop iterates 
over the various grades for each student.

Any program is going to have several phases.  Generally, you:

1) Read in the data

2) Process the data in some way

3) Print out the results

In your case, the processing will be converting the grades to numbers 
(here in the US, we generally assign grades as A=4, B=3, C=2, D=1, F=0, 
but that may differ where you are) and computing the average.

But, start simple.  Write the part of the program which accepts all the 
input first, and just prints it back out, so you know you read it in 
properly.  Once you're sure you've got that working, move on to the next 
phase.  I've been doing this for a long time, and that's still the way I 
attack any new problem.



More information about the Python-list mailing list