11 Replies - 6963 Views - Last Post: 07 December 2010 - 09:52 AM Rate Topic: -----

#1 Sara Mel  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 7
  • Joined: 05-December 10

Student Test Scores Program

Posted 05 December 2010 - 09:40 AM

:cowboy:
I tried to get this program done, but It took me forever, so that is what I have came up with. If you know how to help me get this done, please let me know. We use the JES-Python to write these codes.
Thanxx :rolleyes:
# Take the inputs
fileName = raw_input("Enter the file name: ")

# Open the input file
inputFile = open(fileName, 'r')

outputFile = open("z:/python/payroll.txt", 'w')
printNow ("%-15s%6s%15s" % ("Lat Name", "Test Scores", "Average"))
# Read the data and print the report
name = input("Enter the student's last name: ")
while name != "Done":
    line = inputFile.readline()
    score1 = input("Enter the first score: ")
    score2 = input("Enter the second score: ")
    score3 = input("Enter the third score: ")
    score4 = input("Enter the fourth score: ")
    score5 = input("Enter the fifth score: ")
    if line == "Done":
      break
    dataList = line.split()
    name = dataList[0]
    testScores = int(dataList[1])
    average = score1 + score2 + score3 + score4 + score5 / 5.0
    outputFile.write(name + " "  + str(testScores)  + " " + str(average) + "\n")
    printNow ("%-15s%6d%15.2f" % ("name", "average", "jclass average"))


inputFile.close()
outputFile.close()
    
   

The first part of this program should allow the user to enter a student’s last name and five test scores. The program should accept student data until the word “done” is entered for the student name. This data should be printed to the screen in tabular format. The data also should be stored in a file. One student data be stored per line.

Eample
name:"test score:
John""90, 98 ,67, 86, 78
Mark""70, 80, 90, 75, 98


Second part of this program should read the data from the file. The program should calculate each student’s average and the class average. The program should print the results to the screen.


Example:
name:"test score:""""""""""""average:
John""90, 98, 67, 86, 78"""""""83.8
Mark""70, 80, 90, 75, 98"""""""82.6

Class average: 83.2

This post has been edited by macosxnerd101: 05 December 2010 - 09:44 AM
Reason for edit:: Title renamed to be more descriptive. Titles like "I need help", "Python", and "I'm a noob" are not descriptive titles.


Is This A Good Question/Topic? 0
  • +

Replies To: Student Test Scores Program

#2 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: Student Test Scores Program

Posted 05 December 2010 - 10:09 AM

I see an error in your calculation:
average = score1 + score2 + score3 + score4 + score5 / 5.0



You missed your order of operations....It needs to be this:
average = (score1 + score2 + score3 + score4 + score5) / 5.0



Also, you are leaving out quite a bit of your code AND you're not telling us what is wrong with it. If my solution did not fix it, I advise doing that.
Was This Post Helpful? 1
  • +
  • -

#3 Sara Mel  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 7
  • Joined: 05-December 10

Re: Student Test Scores Program

Posted 05 December 2010 - 10:42 AM

I'm not sure if I'm getting this program right. When I run it, it prints" Enter the file name" I tried to enter the file path, but It said error. I'm not sure how to enter the file path. I tried this: z:/python/payroll.txt but It didnt work with me.
Also, I'm still confused about where to place these codes in the prog:
score1 = input("Enter the first score: ")  

14     score2 = input("Enter the second score: ")  

15     score3 = input("Enter the third score: ")  

16     score4 = input("Enter the fourth score: ")  

17     score5 = input("Enter the fifth score: ") 

Should I write them inside the while loop or outside the loop.
Thank you
Was This Post Helpful? 0
  • +
  • -

#4 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Student Test Scores Program

Posted 05 December 2010 - 11:35 AM

Could you please copy and paste the exact error? Help us help you.
Was This Post Helpful? 0
  • +
  • -

#5 Sara Mel  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 7
  • Joined: 05-December 10

Re: Student Test Scores Program

Posted 05 December 2010 - 11:58 AM

This is the output. It gives errors.
======= Loading Progam =======
Enter the file name: z:/python/payroll.txt
Lat Name Test Scores Average
Enter the student's last name: jone
The error was:jone
Name not found globally.
A local or global name could not be found. You need to define the function or variable before you try to use it in any way.
Please check line 10 of z:\python\payroll.py
>>>

It said, an error was found on line 10 which is the line:
 name = input("Enter the student's last name: ") 

This post has been edited by Sara Mel: 05 December 2010 - 12:04 PM

Was This Post Helpful? 0
  • +
  • -

#6 Guest_c.user*


Reputation:

Re: Student Test Scores Program

Posted 05 December 2010 - 01:16 PM

printNow ("%-15s%6d%15.2f" % ("name", "average", "jclass average"))
what is printNow ?

>>> print "%f" % "abc"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: float argument required, not str
>>> s = "%d" % "abc"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: %d format: a number is required, not str
>>>


This post has been edited by c.user: 05 December 2010 - 01:19 PM

Was This Post Helpful? 0

#7 Sara Mel  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 7
  • Joined: 05-December 10

Re: Student Test Scores Program

Posted 05 December 2010 - 04:47 PM

I still did not get it
Was This Post Helpful? 0
  • +
  • -

#8 Guest_c.user*


Reputation:

Re: Student Test Scores Program

Posted 05 December 2010 - 06:22 PM

comment all lines with this word printNow

like here
# Take the inputs
fileName = raw_input("Enter the file name: ")
 
# Open the input file
inputFile = open(fileName, 'r')

outputFile = open("z:/python/payroll.txt", 'w')
# printNow ("%-15s%6s%15s" % ("Lat Name", "Test Scores", "Average")) # commented
# Read the data and print the report



since some of them may consist incorrect formatting
I suppose you have not also defined that function

This post has been edited by c.user: 05 December 2010 - 06:29 PM

Was This Post Helpful? 0

#9 Sara Mel  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 7
  • Joined: 05-December 10

Re: Student Test Scores Program

Posted 06 December 2010 - 11:48 AM

Here is what I got after I made some changes:
# Take the inputs
fileName = raw_input("Enter the file name: ")

# Open the input file
inputFile = open(fileName, 'w')


# Read the data and print the report
name = raw_input("Enter the student's last name: ")
while name != "Done":
    score1 = input("Enter the first score: ")
    score2 = input("Enter the second score: ")
    score3 = input("Enter the third score: ")
    score4 = input("Enter the fourth score: ")
    score5 = input("Enter the fifth score: ")
    
    
    inputFile.write(name + " " + str(score1) + " "  + str(score2) + " " + str(score3) + " " + str(score4) + " " + str(score5) + "\n")
    name = raw_input("Enter the student's last name: ")
inputFile.close()

outputFile = open(fileName, 'r')
line = outputFile.readline()
while line!= "":
    name = raw_input("Enter the student's last name: ")
    score1 = input("Enter the first score: ")
    score2 = input("Enter the second score: ")
    score3 = input("Enter the third score: ")
    score4 = input("Enter the fourth score: ")
    score5 = input("Enter the fifth score: ")
    line = inputFile.readline()
    dataList = line.split()
    name = dataList[0]
    testScores = (dataList[1])
    average = (score1 + score2 + score3 + score4 + score5) / 5.0
    classAverage = (average / 5.0)
    line = outputFile.readline()
    printNow(name, testScores, average, classAverage)
outputFile.close()
    





When I run it it asks me to enter the student's last name and the five test scores, but when I type the word Done, it didnt output the student's last name, average, and the class average. It asks me again to enter the student's last name. The while loop never stopped. Here is the output:


>>>
======= Loading Progam =======
Enter the file name: c:/payroll77/data.txt
Enter the student's last name: Mark
Enter the first score: 43
Enter the second score: 34
Enter the third score: 34
Enter the fourth score: 34
Enter the fifth score: 43
Enter the student's last name: Done
Enter the student's last name: The error was:java.lang.ThreadDeath
The code has been stopped due to you hitting the stop button.
Please check line 25 of C:\Payroll77\payroll.py
>>>

This post has been edited by Sara Mel: 06 December 2010 - 11:50 AM

Was This Post Helpful? 0
  • +
  • -

#10 Guest_c.user*


Reputation:

Re: Student Test Scores Program

Posted 06 December 2010 - 02:38 PM

# Read the data and print the report

name = ''
while name != "Done":
    name = raw_input("Enter the student's last name: ")
    score1 = input("Enter the first score: ")
    score2 = input("Enter the second score: ")
    score3 = input("Enter the third score: ")
    score4 = input("Enter the fourth score: ")
    score5 = input("Enter the fifth score: ")
    inputFile.write(
        name + " " + str(score1) + " " +
        str(score2) + " " + str(score3) + " " +
        str(score4) + " " + str(score5) + "\n"
    )
inputFile.close()

print 'file closed'




read from an input file
write to an output file
but you have input for write and output for read

This post has been edited by c.user: 06 December 2010 - 02:44 PM

Was This Post Helpful? 0

#11 Sara Mel  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 7
  • Joined: 05-December 10

Re: Student Test Scores Program

Posted 06 December 2010 - 03:40 PM

thank you
Was This Post Helpful? 0
  • +
  • -

#12 Sara Mel  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 7
  • Joined: 05-December 10

Re: Student Test Scores Program

Posted 07 December 2010 - 09:52 AM

I see no experts here!!
Was This Post Helpful? -2
  • +
  • -

Page 1 of 1