Python Simple program

I

indar kumar

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.
 
C

Chris Angelico

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
 
R

Roy Smith

indar kumar said:
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.
 
I

indar kumar

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.
 
R

Roy Smith

indar kumar said:
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.
 
D

Dennis Lee Bieber

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 smells like formal homework... So show us what you've done, and
where you are having problems. Everything in the problem description should
have been covered by the class at this point. Hint: the above description
requires the use of an indefinite loop, console input, console output,
string manipulation, conversion of text input to numbers, another loop of
some form, some simple math (addition and division), and list structures

Unknowns: are course grades provided in 0-100% (if so, what %s map to
what GPA -- oh, is GPA 0-4 or 0-5; integer or real results), letters (A, B,
C, D, E or F), or some other scale. What is a student ID -- some pseudo
random integer, a first name, first&last name, some ad-hoc string?

Are you supposed to collect all the inputs, and then produce a report
with all the GPAs... Or are you going to be generating a GPA for each
entered line as it is entered (mixing the input with the output).

I did just produce a version using REXX that gives this output:

-=-=-=-=-=-
C:\Users\Wulfraed\Documents>homework.rx
Enter data in the form:
student ID: g1 g2 g3 ... gn
Note the : separating the ID from the grades
Grades are expected to be integer percents from 0 to 100%
Enter a blank line to exit data entry


Enter student data (blank to exit):
123: 92 75 83 88

Enter student data (blank to exit):
334: 67 79 40

Enter student data (blank to exit):
see a Name: 125 99 89 92 78

Enter student data (blank to exit):

**************************************************
* Gradebook Summary Report *
**************************************************
Student ID GPA

123 2.450
334 0.867
see a Name 3.160

**************************************************

Press ENTER key to exit...

C:\Users\Wulfraed\Documents>
-=-=-=-=-=-

Of course, I may have the conversion from % to grade point incorrect
(before averaging the grade points -- should 95% be a grade point of 4.0 or
3.5? on a 4pt scale)

-=-=-=-=-
/* ERKK onfrq irefvba bs Clguba ubzrjbex nffvtazrag */

fnl "Ragre qngn va gur sbez:"
fnl " fghqrag VQ: t1 t2 t3 ... ta"
fnl "Abgr gur : frcnengvat gur VQ sebz gur tenqrf"
fnl "Tenqrf ner rkcrpgrq gb or vagrtre crepragf sebz 0 gb 100%"
fnl "Ragre n oynax yvar gb rkvg qngn ragel"
fnl " "

tenqrobbx. = ""
tenqrobbx.0 = 0

qb sberire
fnl " "
fnl "Ragre fghqrag qngn (oynax gb rkvg): "

cnefr chyy fghqragqngn

vs fghqragqngn = "" gura
yrnir

cnefr ine fghqragqngn VQ ":" tenqrf

fghqrag = tenqrobbx.0 + 1

fpber = 0.0
pbhag = 0

qb juvyr tenqrf <> ""
cnefr ine tenqrf tenqr tenqrf
fryrpg
jura tenqr > 100 gura
TC = 4.0
jura tenqr > 90 gura
TC = 3.0 + ((tenqr - 90) / 10)
jura tenqr > 80 gura
TC = 2.0 + ((tenqr - 80) / 10)
jura tenqr > 70 gura
TC = 1.0 + ((tenqr - 70) / 10)
jura tenqr > 60 gura
TC = 0.0 + ((tenqr - 60) / 10)
bgurejvfr TC = 0.0
raq

fpber = fpber + TC
pbhag = pbhag + 1
raq

vs pbhag > 0 gura
nit = fpber / pbhag
ryfr
nit = 0.0

tenqrobbx.fghqrag.vqrag = VQ
tenqrobbx.fghqrag.tcn = nit

tenqrobbx.0 = fghqrag
raq

fnl pbcvrf("*", 50)
fnl "*" || pragre("Tenqrobbx Fhzznel Ercbeg", 48) || "*"
fnl pbcvrf("*", 50)
fnl yrsg("Fghqrag VQ", 25) || evtug("TCN", 25)
fnl ""

qb fghqrag = 1 gb tenqrobbx.0
fnl yrsg(tenqrobbx.fghqrag.vqrag, 25) ||
evtug(sbezng(tenqrobbx.fghqrag.tcn, 1, 3), 25)
raq

fnl ""
fnl pbcvrf("*", 50)
-=-=-=-=-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top