[Tutor] New programmer, need some help getting started on my first project
Bob Gailer
bgailer at alum.rpi.edu
Fri May 19 03:08:44 CEST 2006
Chris Delgado wrote:
> johnf,
>
> Yup, I actually thought that might be my mistake but I forgot to
> actually try it. So I did and revised the code (which I'll post below)
> and now get a syntax error after my heads += line..yikes .
>
> # A program that simulates flipping a coin 100 times and the reports
> the number of heads and tails that were flipped#
>
> import random
>
> heads = 0
> tails = 0
> flips = 0
>
> if flips <= 100:
>
> coin = random.randrange(2)
>
> if coin == 0:
> heads +=
> else:
> tails +=
>
> flips += 1
>
> print "The coin was flipped 100 times and it was heads" + heads +
> "times and tails" + tails + "times!"
>
> raw_input("\n\nPress the Enter key to exit")
Good - you wrote it. Did you run it? Because there are several things
that will lead to "compile errors" and "execution errors". I hope you
run it and think about the errors, then if stumped ask us.
--
Bob Gailer
510-978-4454
More information about the Tutor
mailing list