Grade Book Tutorial

This Is A Basic Grade Book Program

Page 1 of 1

4 Replies - 4652 Views - Last Post: 24 December 2008 - 01:56 AM Rate Topic: -----

#1 Medic873  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 16-November 08

Grade Book Tutorial

Post icon  Posted 18 December 2008 - 03:19 PM

Here is a basic grade book
no real use because it is so basic
# For those of you who dont under stand this please look at Medic873Programing.Com
# The Passwor Is 1337 Once Agian If You Cant Figure This Out
# Thank You For Looking

def Grades():
	password = 1337
	enteredpassword = input ("Please enter the teacher password")
	if enteredpassword == password:
		print ("Please Enter What Student You Are Calling Abone")
		Student1()
		Student2()
		Student3()
		Student5()
		print ("Thank You For Entering All Of Your Grades On Time")
		
	else:
		print ("Invalid Password")

def Student1():
	("Lets Enter The Fist Students Grades")
	assinment1 = input ("Please Enter The Grade The Student Got On The First Assinment")
	assinment2 = input ("Please Enter The Grade The Student Got On The Second Assinment")
	assinment3 = input ("Please Enter The Grade The Student Got On The Third Assinment")
	assinment4 = input ("Please Enter The Grade The Student Got On The Fourth Assinment")
	assinment5 = input ("Please Enter The Grade The Student Got On The Fith Assinment")
	print ("This Students Grade Is")
	grade = assinment1 + assinment2 + assinment3 + assinment4 + assinment5
	print grade / 5
 
def Student2():
	print ("Lets Enter The Second Students Grades")
	assinment21 = input ("Please Enter The Grade The Student Got On The First Assinment")
	assinment22 = input ("Please Enter The Grade The Student Got On The Second Assinment")
	assinment23 = input ("Please Enter The Grade The Student Got On The Third Assinment")
	assinment24 = input ("Please Enter The Grade The Student Got On The Fourth Assinment")
	assinment25 = input ("Please Enter The Grade The Student Got On The Fith Assinment")
	print ("This Students Grade Is")
	grade2 = assinment21 + assinment22 + assinment23 + assinment24 + assinment25 / 5
	print grade2 / 5

def Student3():
	print ("Lets Enter The Third Students Grades")
	assinment31 = input ("Please Enter The Grade The Student Got On The First Assinment")
	assinment32 = input ("Please Enter The Grade The Student Got On The Second Assinment")
	assinment33 = input ("Please Enter The Grade The Student Got On The Third Assinment")
	assinment34 = input ("Please Enter The Grade The Student Got On The Fourth Assinment")
	assinment35 = input ("Please Enter The Grade The Student Got On The Fith Assinment")
	print ("This Students Grade Is")
	grade3 = assinment31 + assinment32 + assinment33 + assinment34 + assinment35 / 5
	print grade3 / 5

def Student5():
	print ("Lets Enter The Fourth Students Grades")
	assinment51 = input ("Please Enter The Grade The Student Got On The First Assinment")
	assinment52 = input ("Please Enter The Grade The Student Got On The Second Assinment")
	assinment53 = input ("Please Enter The Grade The Student Got On The Third Assinment")
	assinment54 = input ("Please Enter The Grade The Student Got On The Fourth Assinment")
	assinment55 = input ("Please Enter The Grade The Student Got On The Fith Assinment")
	print ("This Students Grade Is")
	grade5 = assinment51 + assinment52 + assinment53 + assinment54 + assinment55 / 5
	print grade5 / 5
  



Is This A Good Question/Topic? 0
  • +

Replies To: Grade Book Tutorial

#2 KevinADC  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Grade Book Tutorial

Posted 20 December 2008 - 12:22 PM

Just trying to be helpful....

I think your tutorial could be fleshed out more with some discussion and explanations and possibly links to other python resouces instead of a link to your website which honestly seems like spam to me.

What you have is a code snippet, it is far from a tutorial. There is already a forum for posting code snippets.

Regards,
Kevin
Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5835
  • View blog
  • Posts: 12,690
  • Joined: 16-October 07

Re: Grade Book Tutorial

Posted 20 December 2008 - 12:57 PM

I'm not sure what principals you are trying to teach in you tutorial. The is no explanation to guide me. This doesn't really showcase any elements of Python that a student might have questions about.

To be brutally honest, the code shows some exceptionally bad practices. It's like the before picture for a refactoring test. Cut and paste coding is something we try to teach people not to do. You can probably remove over 75% of the program without loss of function.
Was This Post Helpful? 0
  • +
  • -

#4 chili5  Icon User is offline

  • D.I.C Lover

Reputation: 20
  • View blog
  • Posts: 1,144
  • Joined: 28-December 07

Re: Grade Book Tutorial

Posted 21 December 2008 - 06:18 AM

You have five functions that do the same thing. This isn't a good thing. If you have to copy and paste code, their is a better way.

Why not have a method to display instructions, and a method to make your calculation?
Was This Post Helpful? 0
  • +
  • -

#5 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: Grade Book Tutorial

Posted 24 December 2008 - 01:56 AM

You might like to look at this in Python 3

Shalom,
David
http://developers-he...index.php/topic,46.0.html

# studentGrades.py

# using Python 3

# Globals ...
studentData = {} # using a Python dictionary to hold student grades
myDataFile = 'myData.dat'
dataHasChanged = False
table = ['1st', '2nd', '3rd', '4th', '5th'] # test scores

menuText = \
'''
	1. add/edit
	2. del by idNumber
	3. find idNumber
	4. quit
'''

def getAverage(listOfNumbers):
	sum = 0.0
	for num in listOfNumbers:
		sum += num;
	return sum/len(listOfNumbers)

def getGrades():
	grades = []
	dataOk = False
	while not dataOk:
		try:
			for item in range(len(table)):
				nth = table[item]
				result = eval(input('Enter the grade for the ' + nth + ' test : '))
				grades.append(result)
			dataOk = True
		except:
			print('A data entry error occured ...')	 
	print('Average for this student is', getAverage(grades))
	return grades

def showAll(stud_data):
	for idNum in sorted(stud_data):
		print('Student ID', idNum, 'has scores', stud_data[idNum], end=' ')
		print('with an average score of', getAverage(stud_data[idNum]))
	
def addEdit(stud_data):
	done = False
	while not done:
		try:
			idNumber = int(input('Enter student idNumber : '))
			done = True
		except:
			print('Entry error ... Use integers only for the ID number.')
		
	if idNumber in stud_data:
		reply  = input('This ' + str(idNumber) + \
					   ' number is used ... Exit/Overwrite (E/O) ? ')
		if not(reply == 'O' or reply =='o'):
			return
		
		del(stud_data[idNumber])

	# if reach here ... then update studentData dictionary			
	stud_data[idNumber] = getGrades()
	print('Student ID', idNumber, 'data file has been added.')
	global dataHasChanged
	dataHasChanged = True

def fileData(stud_data):
	f = open(myDataFile, 'w');
	for idNum in stud_data:
		f.write(str(idNum) + '\n')
		for result in stud_data[idNum]:
			f.write(str(result) + '\n')
	f.close()
	print('Student data file was updated.')
	global dataHasChanged
	dataHasChanged = False # reset flag

def inputFile(stud_data):
	# see if file exists ...
	try:
		f = open(myDataFile, 'r')
	except:
		print('No student file exists yet ...')
		return
		
	#if we reach here the file exits ... so ...
	lines = f.readlines()
	f.close()
	
	numItems = len(table)+1 # numItems to read from file for each record
	for n in range(len(lines)//numItems): # note // for integer division now
		idNum = int(lines[n*numItems])
		tmp =[]
		for i in range(len(table)):
			tmp.append(eval(lines[n*numItems+i+1]))   
		stud_data[idNum] = tmp

def findStud(stud_data):
	try:
		idNum = int(input('Student idNum of record to find : '))
	except:
		print('Entry error ... Use integers only for the ID number.')
		return
	
	if idNum in stud_data:
		print('Student ID', idNum, 'has scores', stud_data[idNum], end=' ')
		print('with an average score of', getAverage(stud_data[idNum]))
	else:
		print('Not found ...')

def delStud(stud_data):
	try:
		idNum = int(input('Student idNum of record to delete : '))
	except:
		print('Entry error ... Use integers only for the ID number.')
		return
		
	if idNum in stud_data:
		del(stud_data[idNum])
		global dataHasChanged
		dataHasChanged = True
		print('Student ID', idNum, 'data file has been deleted.')
	else:
		print('Not found ...')
	
def main():
	inputFile(studentData)
	more = True
	while more:
		showAll(studentData)
		print(menuText)
		choice = input('Your choice ? ') #1,2,3,4
		if choice == '1':
			addEdit(studentData)
			if dataHasChanged: fileData(studentData)
		elif choice == '2':
			delStud(studentData)
			if dataHasChanged: fileData(studentData)
		elif choice == '3':
			findStud(studentData)
			input("Press 'Enter' to continue ...")
		elif choice == '4':
			more = False
		else:
			print('Not implemented yet ...')
		print()

if __name__ == "__main__":
	main()

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1