Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Python Simple program

23 views
Skip to first unread message
Message has been deleted

Chris Angelico

unread,
Jan 18, 2014, 1:11:24 PM1/18/14
to pytho...@python.org
On Sun, Jan 19, 2014 at 5:00 AM, indar kumar <indark...@gmail.com> 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.

No.

This is homework, and you should do it yourself - otherwise you are
cheating yourself, cheating on your course, and ultimately, cheating
an employer by making him/her think you know how to do something when
you don't.

If you write the code yourself and then have questions, then by all
means, bring those questions to us! We're happy to help you learn. But
that's quite different from outright doing your homework for you.

ChrisA

Roy Smith

unread,
Jan 18, 2014, 1:27:28 PM1/18/14
to
In article <a2e2f4a7-4c86-440e...@googlegroups.com>,
indar kumar <indark...@gmail.com> 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.

This sounds like a homework problem for a basic programming course.

Rather than write your program for you, let me give you a few broad
hints. You're going to need to call raw_imput() in a loop to read in
your data, then use split() to break the line up into fields, and
another loop to iterate over the individual grades.

See what progress you can make with that, and if you get stuck, come
back with whatever code you've written so far, and more specific
questions.
Message has been deleted

Roy Smith

unread,
Jan 18, 2014, 2:07:16 PM1/18/14
to
In article <60955b74-7bc8-4c72...@googlegroups.com>,
indar kumar <indark...@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.
Message has been deleted
0 new messages