School Assignment having trouble Teacher = asshat

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

School Assignment having trouble Teacher = asshat

Post by coldghost213 on Wed Oct 08, 2008 12:57 pm
([msg=13398]see School Assignment having trouble Teacher = asshat[/msg])

My goal = "Write a program that will allow a teacher to calculate the average test score for a certain number of students. The teacher can enter the number of students who took the test, and then the score for each student. Your program will then calculate the average score and print out the results. Your program must use the appropriate loop, modules, and run multiple times for different sets of test scores."

This is what I attempted to write so far
It says that number students is not defined on the line where getGrades() is called
It looks right to me =\ teacher just says to figure it out myself when I am stumped

Code: Select all
#This program is used to find the students average
#This code is written by Charles Barnett on October 7
#This is the main function
def main():
    retry = 'y'
    while retry == 'y' or retry == 'Y':
       getStudents()#This calls number of students
       getGrades(numberStudents)#This calls the total grades
       getAverage(testGrades, numberStudents)#This determines the average
       printInfo(studentsAverage)#This prints out the results
       retry = input('Would you like to try another class? (N for No Y for Yes)')

#This function gets the number of students in a classroom
def getStudents():
   numberStudents = input('Please enter number of students in classroom ')
   numberStudents = int(numberStudents)
   return numberStudents

#This function gets the total test score
def getGrades(numberStudents):
   for number in range(numberStudents):
    grade = input('Please enter students score')
    grade = float(grade)
    testGrades = testGrades + grade
    return testGrades


#This function gets the average score of all the students
def getAverage(testGrades, numberStudents):
   studentsAverage = testGrades / numberStudents
   return studentsAverage

#This function prints out the students average scores
def printInfo(studentsAverage):
   print 'Your total average is ', studentsAverage

main()

--------------------------------------------------------------------------------------------------------------

Edit: woops sorry I didn't know how I posted twice, well anyways please post here
coldghost213
New User
New User
 
Posts: 15
Joined: Wed Jun 25, 2008 9:04 pm
Blog: View Blog (0)


Re: School Assignment having trouble Teacher = asshat

Post by tgoe on Thu Oct 09, 2008 1:05 pm
([msg=13455]see Re: School Assignment having trouble Teacher = asshat[/msg])

You aren't saving your return values!
User avatar
tgoe
Contributor
Contributor
 
Posts: 665
Joined: Sun Sep 28, 2008 2:33 pm
Location: q3dm7
Blog: View Blog (0)



Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests