[Tutor] On a looping input, subsequent inputs are hidden
Steven D'Aprano
steve at pearwood.info
Wed Jun 12 04:19:57 CEST 2013
On 12/06/13 03:53, Jim Mooney wrote:
> But I do like the idea of using plain old words, like "bad" as a
> switch, instead of some inscrutable program-switch ;')
I don't. Trust me on this, you will regret it. As the Zen of Python says, "Explicit is better than implicit". It may seem like a good idea now, but some day you'll write code like this:
def reward(msg):
print(msg)
if 'link' in msg:
administer_electric_shock()
else:
give_cake()
def administer_test(username):
score = 0
for question, answer in list_of_tests:
response = input(question)
if response == answer:
score += 1
if score > len(list_of_tests):
msg = "Congratulations %s, you have passed!" % username
else:
msg = "%s, you are the weakest link!" % username
reward(msg)
Can you see the bug?
--
Steven
More information about the Tutor
mailing list