On 17May2017 12:26, Grace Sanford wrote:
Theoretically, the following code is suppose to check if the user has won a
tic tac toe game by checking if there are all "X"s in either the
horizontal, vertical, or diagonal lines of a grid (represented by a list
with "board" with
On 17/05/17 17:26, Grace Sanford wrote:
> with "board" with elements 0-8). If one of these is the case, it is
> suppose to print the "You won" string. Nevertheless, when I change list
> variable to reflect one of these conditions, there is no printing
> occurring. I cannot figure out why.
You
Theoretically, the following code is suppose to check if the user has won a
tic tac toe game by checking if there are all "X"s in either the
horizontal, vertical, or diagonal lines of a grid (represented by a list
with "board" with elements 0-8). If one of these is the case, it is
suppose to
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
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 figure out
On Sat, Oct 4, 2008 at 5:11 AM, David [EMAIL PROTECTED] wrote:
Hello!!
snip
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,
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...
-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 as
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:
if
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:
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 an
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):
Return a
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
it to
, 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'),
(70, 79,'C'),
(60, 69,'D
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
- 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 different:
import string
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 for something completely
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 conversion program
Dragos Ionescu
Dragos Ionescu wrote:
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 conversion
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 string -
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Just the way IDLE works. Unexpected, but certainly not a bug, I'd say.
Andreas
Grant Hagstrom wrote:
A bug or feature in the IDLE of python 2.5?
pre-step: save the following file to your computer:
# file mylist.py
jobs = [
'Lions',
A bug or feature in the IDLE of python 2.5?
pre-step: save the following file to your computer:
# file mylist.py
jobs = [
'Lions',
'SysTest',
'trainDD',
'Cats',
'train',
'sharks',
'whale',
]
Step 1.
copy, paste this script into the idle
Hey everyone, i believe i might have found a bug in
python? im not sure, heres a screen shot.
http://img151.imageshack.us/img151/4268/pythonbug8by.jpg
When i type
number + 1
and print it,
It adds one,
But when i use a number = number + 1
right after the value stays the same,
Now i thought that
HA! ignore me, im stupid, XD i knew i should have
waited untill morning =P,
No bug, the number = number was just point to the old
number which was one number lower,
sorry. night =P
Oh i see someone replied -_- sorry lol
___
Tutor maillist -
On Fri, 21 Apr 2006, ryan luna wrote:
HA! ignore me, im stupid, XD i knew i should have waited untill morning
=P, No bug, the number = number was just point to the old number which
was one number lower, sorry. night =P
Get some sleep. *grin*
But when i use a number = number + 1
right after the value stays the same,
I'm not sure what you mean by that.
Now i thought that number = number + 1 just wasn't
vailed in python untill i tried it again and it
worked,
variable = variable + 1
is perfectly valid. It is not the normal math
Hi Ryan,
I see what confused you; the
number + 1
6
print number
5
part. Yeah, it's only evaluating the the first one. So you're asking
it What's number + 1?
Whereas,
number = number + 1
or
number += 1
Is saying Make number equal number plus 1
Ha, it's all a learning experience.
Hi, just a recommendation: try not to assume a bug beforehand, that's a
quick way to get flames or just get plain ignored, especially in a list
for beginners.
The * is being given equal priority to %.
Why isn't % given higher priority than *?
Why should it? Doesn't it make sense that as
a = 1
a2 = a%2
a2
1
8*a2
8
8*(a%2)
8
8*a%2
0
The * is being given equal priority to %.
Why isn't % given higher priority than *?
Also, why am I getting a syntax error in the following?
The def in the definition of the second function is being highlighted.
IDLE 1.1.2
def
On 20/02/06, Kermit Rose [EMAIL PROTECTED] wrote:
8*a%2
0
The * is being given equal priority to %.
Why isn't % given higher priority than *?
Calling it a bug is a bit harsh when it's documented that way :-)
See: http://docs.python.org/ref/summary.html
*, / and % all have the same
8*a%2
0
The * is being given equal priority to %.
Why isn't % given higher priority than *?
Because that's the way Guido designed I guess. ;-)
Although why would you expect % to be higher precedence than *?
You can always use parentheses, and if in any doubt should
do so.
Also, why am
31 matches
Mail list logo