[Tutor] My First Program

Joseph Quigley cpu.crazy at gmail.com
Thu Dec 8 21:14:29 CET 2005


>
>
> Hi! My first "ever" program that I've created is a simple game called
> "State
> Capitals". It's straight forward; 5 simple questions about state capitals
> in
> a non-GUI format. Can someone look over my code and offer tips,
> suggestions,
> criticism? Also, I'd like to be able to end the program if the user misses
> 3
> questions (i.e., kick them out after the 3rd wrong answer). How can I do
> this? Thanks!
>
>
> print "\nState Capitals! Answer a or b to the following questions.\n"
> question = raw_input("Question 1 - What is the capital of NC, a: Raleigh
> or
> b: Atlanta? ")
> if question == "a":
>         print "Yes\n"
> else:
>         print "WRONG\n"
>
> question = raw_input("Question 2 - What is the capital of SC, a:
> Greenville
> or b: Columbia? ")
> if question == "b":
>         print "Yes\n"
> else:
>         print "WRONG\n"
>
> question = raw_input("Question 3 - What is the capital of NY, a: Albany or
> b: Buffalo?")
> if question == "a":
>         print "Yes\n"
> else:
>         print "WRONG\n"
>
> question = raw_input("Question 4 - What is the capital of OH, a: Cleveland
> or b: Columbus? ")
> if question == "b":
>         print "Yes\n"
> else:
>         print "WRONG\n"
>
> question = raw_input("Question 5 - What is the capital of TX, a: Houston
> or
> b: Austin? ")
> if question == "b":
>         print "Yes\n"
> else:
>         print "WRONG\n"
>

Hi! Glad you picked up Python. You'll probably enjoy it.

This might be over your head, but I'd use functions for your Yes and WRONG:

def yes():
    print "Yes\n"
def WRONG():
    print "WRONG\n"

# Now for the sample code:
question = raw_input("Question 4 - What is the capital of OH, a: Cleveland
or b: Columbus? ")
if question == "b":
        yes()
else:
        WRONG()

Hope this helps.
Joe


--
There are 10 different types of people in the world.
Those who understand binary and those who don't.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051208/fa630dec/attachment.html


More information about the Tutor mailing list