problem in python. how to do this...?!

Thread Solved

Join Date: Oct 2007
Posts: 4
Reputation: CoolFool is an unknown quantity at this point 
Solved Threads: 0
CoolFool CoolFool is offline Offline
Newbie Poster

problem in python. how to do this...?!

 
0
  #1
Oct 30th, 2007
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...
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 152
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: problem in python. how to do this...?!

 
0
  #2
Oct 30th, 2007
Suppose that you were the computer; how would you solve this problem? For example, I give you an 86. How do you know to return a 'B'?

Write a short plan that a human could follow; then turn it into a Python program.

Post your plan here, if you like, and we can help refine it.

Jeff
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 4
Reputation: CoolFool is an unknown quantity at this point 
Solved Threads: 0
CoolFool CoolFool is offline Offline
Newbie Poster

Re: problem in python. how to do this...?!

 
0
  #3
Oct 30th, 2007
Here is what i've got...

  1. def main():
  2.  
  3. letter(A) = ["100", "99", "98", "97",
  4. "96", "95", "94", "93", "92", "91", "90"]
  5. letter2(B) = ["89", "88", "87",
  6. "86", "85", "84", "83", "82", "81", "80"]
  7. #and so on... but afeter this i have no idea how to make computer look at the
  8. #right list and print the corresponding grade...
  9.  
  10.  
  11.  
  12.  
  13. score = input("Enter quiz score: ")
  14.  
  15.  
  16. #over here... how do i make computer look at letter
  17.  
  18. print "Letter grade is", letter[score-1] + "."
  19.  
  20. main()
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 4
Reputation: CoolFool is an unknown quantity at this point 
Solved Threads: 0
CoolFool CoolFool is offline Offline
Newbie Poster

Re: problem in python. how to do this...?!

 
0
  #4
Oct 30th, 2007
please somebody answer...
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 152
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: problem in python. how to do this...?!

 
0
  #5
Oct 30th, 2007
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

  1. get the numeric score
  2. look up the score in a list # < This is the part you're trying to solve.
  3. 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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 4
Reputation: CoolFool is an unknown quantity at this point 
Solved Threads: 0
CoolFool CoolFool is offline Offline
Newbie Poster

Re: problem in python. how to do this...?!

 
0
  #6
Oct 31st, 2007
Hey guy this is auctualy the answer...

you've got to write the code like this...


...
grades = 60 * F + 10 * d + 10 * c + 10 * B + 11 * A

this will give you 60 Fs and 10 Ds and so on...

just have it... maybe it will help somebody...
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,667
Reputation: vegaseat is a glorious beacon of light vegaseat is a glorious beacon of light vegaseat is a glorious beacon of light vegaseat is a glorious beacon of light vegaseat is a glorious beacon of light 
Solved Threads: 1093
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: problem in python. how to do this...?!

 
0
  #7
Oct 31st, 2007
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 ...
  1. if score < 60:
  2. grade = 'F'
If your score is higher than or equal to 90, the grade will be an A ...
  1. if score >= 90:
  2. grade = '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 ...
  1. if score >= 80 and score <= 89:
  2. grade = 'B'
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.
Last edited by vegaseat; Oct 31st, 2007 at 10:16 am.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,202
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 341
woooee woooee is offline Offline
Nearly a Posting Virtuoso

Re: problem in python. how to do this...?!

 
0
  #8
Nov 1st, 2007
You can also use:
  1. if score < 60:
  2. grade="F"
  3. elif score < 70:
  4. grade="D"
  5. elif score < 80:
  6. grade="C"
  7. elif score < 90:
  8. grade="B"
  9. elif score < 101:
  10. grade="A"
  11. else:
  12. print score, "is bogus"
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.
Last edited by woooee; Nov 1st, 2007 at 6:24 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1387 | Replies: 7
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC