Image

Listens: The Samples - Taking Us Home | Powered by Last.fm

Tough Decisions

I've been learning Python, slowly, and it's getting harder and harder to overcome obstacles in my coding. This is why I dropped the 'CS' emphasis from my degree.

My most recent assignment was to give a user three tries to guess the writer's name. No biggie in itself, but most sites don't allow me, the writer, to use a '.' so I go by dotplaid. Some folks know me as .plaid, though, and neither group of users should be punished, so I wanted to elegantly check for both .plaid and dotplaid - not so easy for my addled brain. In fact I gave up; I'll come back at some point when I have a better handle on what I'm doing.

Exercise 10 code:
#Write a program that has a user guess your name, but they only get 3 chances to do so until the program quits.

guess_attempt = 0
guess = "text"

while guess_attempt < 3 and not guess == ".plaid":
    guess = raw_input ("Enter name here: ")
    guess_attempt = guess_attempt + 1

if guess_attempt <= 2 or guess == ".plaid":
    print "Hi, ", guess
else:
    print "Away!"

I had lines while guess_attempt < 3 and not guess == (".plaid" or "dotplaid"): and if guess_attempt <= 2 or guess == (".plaid" or "dotplaid):, but only .plaid would trigger correctly, not the second or term. Grrrr