[docs] Else ,elif

Georg Brandl georg at python.org
Sun Oct 6 09:15:49 CEST 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 25.09.2013 20:45, schrieb abjimnen at aol.com:
> I am new to programming but have been seriously been bitten by the buy and
> I am working with the book Python for Dummies by Stef Maruch and Aahz
> Maruch. I am working on a coin toss program which is suppose to  be
> something like   MY issue is that when I try to use the else or elif
> function  it comes back as SyntaxError: invalid syntax  and search as I
> might I can' t seem to find help to address this one issue.  And I was
> hoping you guys can lead me someplace to solve this.   I am using Python
> 3.3.2 on a Mac. Yours Truly Roman
> 
> import random userinput = ' ' print"Now tossing a coin    " while
> userinput.lower() != "q": flip = random.choice(['heads', 'tails']) if flip
> == 'heads': headcount+= 1 print"heads! the number of heads is now %d"%
> tailcount else: tailcount += 1 print"tails! the number of tails is now %d"%
> tailcount print"press 'Q' to quit", userinput = raw_input("or another key
> to toss again:") print" the total number of heads:", headcount print"the
> total number off tails:", tailcount

Hi,

you will have to remove indentation of the "else" clause, so that the
"else" line is indented the same as the "if" line.

Please write to the tutor at python.org list if you have further questions; this
list is for the discussion and improvement of the Python docs.

cheers,
Georg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.21 (GNU/Linux)

iEYEARECAAYFAlJRDiUACgkQN9GcIYhpnLBlHgCffjTZPw0ikR137SOapjm+a9ip
YjsAnA6BBKyBj7FwbWitwM6zdHsPihyw
=d9rO
-----END PGP SIGNATURE-----


More information about the docs mailing list