Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64239 > unrolled thread

Python Simple program

Started byindar kumar <indarkumar59@gmail.com>
First post2014-01-18 10:00 -0800
Last post2014-01-18 15:25 -0500
Articles 6 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Python Simple program indar kumar <indarkumar59@gmail.com> - 2014-01-18 10:00 -0800
    Re: Python Simple program Chris Angelico <rosuav@gmail.com> - 2014-01-19 05:11 +1100
    Re: Python Simple program Roy Smith <roy@panix.com> - 2014-01-18 13:27 -0500
    Re: Python Simple program indar kumar <indarkumar59@gmail.com> - 2014-01-18 10:49 -0800
      Re: Python Simple program Roy Smith <roy@panix.com> - 2014-01-18 14:07 -0500
    Re: Python Simple program Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-18 15:25 -0500

#64239 — Python Simple program

Fromindar kumar <indarkumar59@gmail.com>
Date2014-01-18 10:00 -0800
SubjectPython Simple program
Message-ID<a2e2f4a7-4c86-440e-839f-09745735efe0@googlegroups.com>
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.

[toc] | [next] | [standalone]


#64241

FromChris Angelico <rosuav@gmail.com>
Date2014-01-19 05:11 +1100
Message-ID<mailman.5680.1390068689.18130.python-list@python.org>
In reply to#64239
On Sun, Jan 19, 2014 at 5:00 AM, indar kumar <indarkumar59@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

[toc] | [prev] | [next] | [standalone]


#64243

FromRoy Smith <roy@panix.com>
Date2014-01-18 13:27 -0500
Message-ID<roy-63C227.13272818012014@news.panix.com>
In reply to#64239
In article <a2e2f4a7-4c86-440e-839f-09745735efe0@googlegroups.com>,
 indar kumar <indarkumar59@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.

[toc] | [prev] | [next] | [standalone]


#64246

Fromindar kumar <indarkumar59@gmail.com>
Date2014-01-18 10:49 -0800
Message-ID<60955b74-7bc8-4c72-94e1-849015985034@googlegroups.com>
In reply to#64239
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. 

[toc] | [prev] | [next] | [standalone]


#64250

FromRoy Smith <roy@panix.com>
Date2014-01-18 14:07 -0500
Message-ID<roy-B297DE.14071618012014@news.panix.com>
In reply to#64246
In article <60955b74-7bc8-4c72-94e1-849015985034@googlegroups.com>,
 indar kumar <indarkumar59@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.

[toc] | [prev] | [next] | [standalone]


#64251

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2014-01-18 15:25 -0500
Message-ID<mailman.5686.1390076740.18130.python-list@python.org>
In reply to#64239
On Sat, 18 Jan 2014 10:00:47 -0800 (PST), indar kumar
<indarkumar59@gmail.com> declaimed the following:

>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)
-=-=-=-=-
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web