[Tutor] Improving My Simple Game Code for Speed, Memory and Learning
Danny Yoo
dyoo at hashcollision.org
Tue Jan 6 00:21:39 CET 2015
Apologies; haven't had time to look at this thread carefully yet.
Busy start of the new year. :P
Minor comment: you can improve this snippet:
if total == 17 or total == 21 or total == 28 or total == 29 or \
total == 31 or total == 42 or total == 45 or total == 46 \
or total == 49 or total == 58:
by testing to see if total is an element in a sequence:
if total in (17, 21, 28, ...):
which you can read as: "If 'total' is a member of the tuple (17, 21, 28, ...)"
This will let you avoid having to write so much to check that condition.
The other comment I'd make is to start thinking about how you'd _test_
your program automatically.
There's enough non-trivial logic that I'm not convinced that it
actually does what you think it does. But then again, I haven't read
it closely, so maybe it's trivial. Even so, tests help by acting as
regression detectors: you have more freedom to start changing
implementation, and the tests will catch mistakes for you.
By "tests", I mean the kind of thing presented by:
http://www.diveintopython3.net/unit-testing.html
Good luck to you!
More information about the Tutor
mailing list