| | |
problem in python. how to do this...?!
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Solved Threads: 0
Hello EVeryone...
I really need some help with this problem...
A certain CS professor gives 100 - point quiz graded on scale
90 - 100:A
80 - 89:B
70- 79: C ,
60 - 60
<60 :F
I need to write a program that eccepts an exam score as input and prints the corresponding grade...
First question i have is should i use Lists to present the numbers in the code? or is there another way... what would be the best....
Thanx...
I really need some help with this problem...
A certain CS professor gives 100 - point quiz graded on scale
90 - 100:A
80 - 89:B
70- 79: C ,
60 - 60
<60 :F
I need to write a program that eccepts an exam score as input and prints the corresponding grade...
First question i have is should i use Lists to present the numbers in the code? or is there another way... what would be the best....
Thanx...
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Solved Threads: 0
Here is what i've got...
Python Syntax (Toggle Plain Text)
def main(): letter(A) = ["100", "99", "98", "97", "96", "95", "94", "93", "92", "91", "90"] letter2(B) = ["89", "88", "87", "86", "85", "84", "83", "82", "81", "80"] #and so on... but afeter this i have no idea how to make computer look at the #right list and print the corresponding grade... score = input("Enter quiz score: ") #over here... how do i make computer look at letter print "Letter grade is", letter[score-1] + "." main()
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 152
OK, so that's code...but it's not a plan. The plan is higher-level and leaves the details for later.
Reading between the lines, your plan seems to be something like
The way that you are trying to look up the grade in the list is what dictionaries are made for, so when you get there in your course, think of this problem.
For now, you need something different.
Here's a thought: suppose you had
grades = ["F","D","C","B","A"]
so that grades[0] = "F", etc.
Can you come up with a way to turn a number from 0 - 100 into the right number from 0 - 4 so that you could look up the number on the list?
OR
Could you use a series of if-elif statements to figure out the right letter to print?
Jeff
Reading between the lines, your plan seems to be something like
Python Syntax (Toggle Plain Text)
get the numeric score look up the score in a list # < This is the part you're trying to solve. print result
The way that you are trying to look up the grade in the list is what dictionaries are made for, so when you get there in your course, think of this problem.
For now, you need something different.
Here's a thought: suppose you had
grades = ["F","D","C","B","A"]
so that grades[0] = "F", etc.
Can you come up with a way to turn a number from 0 - 100 into the right number from 0 - 4 so that you could look up the number on the list?
OR
Could you use a series of if-elif statements to figure out the right letter to print?
Jeff
Look at your conditions:
90 - 100: A
80 - 89: B
70 - 79: C
60 - 69: D
< 60: F
The last line says, if the score is less than 60, then the grade is an F. That would be the easiest to write for the computer to understand ...
If your score is higher than or equal to 90, the grade will be an A ...
Now the logic expression for grade B is more complex. If the score is greater than or equal to 80 and the score is less than or equal to 89, then the grade is a B. For the computer ...
The conditions are similar for grades C and D.
Once you have all your if statements written, assign score a value (0 to 100), send it through the ifs, and at the end print your resulting grade to test it all out.
90 - 100: A
80 - 89: B
70 - 79: C
60 - 69: D
< 60: F
The last line says, if the score is less than 60, then the grade is an F. That would be the easiest to write for the computer to understand ...
python Syntax (Toggle Plain Text)
if score < 60: grade = 'F'
python Syntax (Toggle Plain Text)
if score >= 90: grade = 'A'
python Syntax (Toggle Plain Text)
if score >= 80 and score <= 89: grade = 'B'
Once you have all your if statements written, assign score a value (0 to 100), send it through the ifs, and at the end print your resulting grade to test it all out.
Last edited by vegaseat; Oct 31st, 2007 at 10:16 am.
May 'the Google' be with you!
•
•
Join Date: Dec 2006
Posts: 1,202
Reputation:
Solved Threads: 341
You can also use:
but as stated earlier, it depends on what makes sense to you. i.e. what the outline is. Also, do you want to keep track of multiple scores for mulitple people. If so, that adds another dimension to the problem.
Python Syntax (Toggle Plain Text)
if score < 60: grade="F" elif score < 70: grade="D" elif score < 80: grade="C" elif score < 90: grade="B" elif score < 101: grade="A" else: print score, "is bogus"
Last edited by woooee; Nov 1st, 2007 at 6:24 pm.
![]() |
Similar Threads
- newbee: python link objects (Python)
- python extending with c(doubts) (Python)
- Python Error-- cannot find file (Python)
- Python Stat points... (Python)
- Comparing Python and C, Part 1, Integer Variables (Python)
- Equation Solver (Python)
- I have a problem with python....help (Python)
- Pygame crashing (Python)
- weird cgi problem (Linux Servers and Apache)
Other Threads in the Python Forum
- Previous Thread: Temperature converter program
- Next Thread: Is It Prime Help
Views: 1387 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Python
application array beginner c++ c/c++ change character class client code command compression convert count create csv ctypes cx-freeze database dictionary django dll error examples excel exe extensions fdlib file float format framework ftp function graphics gui homework image images import input library line linux list lists logging loop loops microcontroller mouse mysql mysqldb number numbers output parse parsing path pointer port prime processing program programming py2exe pygame pygtk pyqt python random raw_input recursion recursive redirect remote scrolledtext server socket ssh stdout string strings syntax table terminal text thread threading tkinter transparency tuple tutorial ubuntu unicode variable variables web windows wxpython






