"Dragos Ionescu" <[EMAIL PROTECTED]> wrote
David try this:
score = input("What is your exam score: (0-100)? ")
No, please don't! input has several security issues, it is
much better to use raw_input but convert the result to
the type you need:
score = int(raw_input("What is your exam sc
"David" <[EMAIL PROTECTED]> wrote
When I run it from the idle it works perfect, but when I run it from
a
file I get none, why is that?
score = 66
Here you directly assign a number to score
#!/usr/bin/python
score = raw_input("What is your exam score: (0-100)? ")
Here you assign a str
"Kent Johnson" <[EMAIL PROTECTED]> wrote
It's not too bad but I would probably use a dictionary rather
than the list - which avoids the index problem
Not sure how the dict is better - in either case, leaving off the
grade corresponding to a score of 100 will raise an exception.
Sure, you co
utor@python.org>
> Sent: Saturday, October 4, 2008 10:15:10 PM
> Subject: Re: [Tutor] bug in exam score conversion program
>
> Lots of good responses. And now for something completely different:
>
> import string
> x = string.maketrans('567891', 'FDCBAA
Original Message
From: Steve Willoughby <[EMAIL PROTECTED]>
To: Dragos Ionescu <[EMAIL PROTECTED]>
Cc: bob gailer <[EMAIL PROTECTED]>; David <[EMAIL PROTECTED]>; tutor@python.org
Sent: Saturday, October 4, 2008 11:04:30 PM
Subject: Re: [Tutor] bug in exam score co
Dragos Ionescu wrote:
- Original Message
From: bob gailer <[EMAIL PROTECTED]>
To: David <[EMAIL PROTECTED]>
Cc: tutor@python.org
Sent: Saturday, October 4, 2008 10:15:10 PM
Subject: Re: [Tutor] bug in exam score conversion program
Lots of good responses. And now f
- Original Message
From: bob gailer <[EMAIL PROTECTED]>
To: David <[EMAIL PROTECTED]>
Cc: tutor@python.org
Sent: Saturday, October 4, 2008 10:15:10 PM
Subject: Re: [Tutor] bug in exam score conversion program
Lots of good responses. And now for something completely differ
Lots of good responses. And now for something completely different:
import string
x = string.maketrans('567891', 'FDCBAA')
score = raw_input('score>')
print "Your grade is:", score[0].translate(x)
--
Bob Gailer
Chapel Hill NC
919-636-4239
When we take the time to be aware of our feelings and
tutor@python.org
Sent: Saturday, October 4, 2008 7:55:57 PM
Subject: Re: [Tutor] bug in exam score conversion program
When I run it from the idle it works perfect, but when I run it from a
file I get none, why is that?
>>> grades = [ (90,100,'A'),
(80, 89,'B'
On Sat, Oct 4, 2008 at 12:55 PM, David <[EMAIL PROTECTED]> wrote:
> When I run it from the idle it works perfect, but when I run it from a
> file I get none, why is that?
> score = raw_input("What is your exam score: (0-100)? ")
The value returned from raw_input() is a string; you have to convert
When I run it from the idle it works perfect, but when I run it from a
file I get none, why is that?
>>> grades = [ (90,100,'A'),
(80, 89,'B'),
(70, 79,'C'),
(60, 69,'D'),
( 0, 59,'F'),
]
>>> score = 66
>>> def getGrade(score):
"""
On Sat, Oct 4, 2008 at 9:45 AM, Alan Gauld <[EMAIL PROTECTED]> wrote:
> It's not too bad but I would probably use a dictionary rather
> than the list - which avoids the index problem
Not sure how the dict is better - in either case, leaving off the
grade corresponding to a score of 100 will raise
On Sat, Oct 4, 2008 at 10:31 AM, Brian C. Lane <[EMAIL PROTECTED]> wrote:
>for g in grades:
>if (score <= g[1]) and (score >= g[0]):
>return g[2]
I think tuple unpacking makes code like this more readable:
for lower, upper, grade in grades:
if lower <= score <= upper:
"Brian C. Lane" <[EMAIL PROTECTED]> wrote
# min, max, grade
grades = [ (90,100,'A'),
(80, 89,'B'),
(70, 79,'C'),
(60, 69,'D'),
( 0, 59,'F'),
]
def getGrade(score):
"""
Return a letter grade based on a score
"""
for g in grades:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
David wrote:
> Hello!!
>
> I just completed exercise 7 (chapter 4) in Zelle's book:
> "A certain CS professor gives 100-point exams that are graded on the
> scale 90–100:A, 80–89:B, 70–79:C, 60–69:D, 60:F. Write a program that
> accepts an exam score
"David" <[EMAIL PROTECTED]> wrote
I am quite happy with my code, but there is a bug: if the score is
100, then the program calculates 100/10 = 10. However, the tuple
runs to 9, leaving me with an error message: IndexError: tuple index
out of range
I can't figure out how to solve that problem
On Sat, Oct 4, 2008 at 5:11 AM, David <[EMAIL PROTECTED]> wrote:
> Hello!!
I can't figure out how to solve that problem...
> I also suspect that my code clearly exposes me as a beginner :-) What would
> be the pythonic way of solving that exercise?
>
> # exam score to grade conversion
> # Zelle
On Sat, Oct 4, 2008 at 12:11, David <[EMAIL PROTECTED]> wrote:
> I am quite happy with my code, but there is a bug: if the score is 100, then
> the program calculates 100/10 = 10. However, the tuple runs to 9, leaving me
> with an error message: IndexError: tuple index out of range
>
> I can't figu
Hello!!
I just completed exercise 7 (chapter 4) in Zelle's book:
"A certain CS professor gives 100-point exams that are graded on the
scale 90–100:A, 80–89:B, 70–79:C, 60–69:D, 60:F. Write a program that
accepts an exam score as input and prints out the corresponding grade."
I am quite happy
19 matches
Mail list logo