Aug-19-2018, 03:33 AM
As I thought. Your call to
About the while statement. While loops are for when you're not sure how many times through the loop you'll want to go. When you know how many times through the loop you want to go, use a for loop. In your case you would want
There's also another function in random that you might be interested in: choice.
random.randint(1, 2)
is what flips the coin. But that is not part of your loop. To be part of the loop it needs to be part of the indented block of code under the while statement.About the while statement. While loops are for when you're not sure how many times through the loop you'll want to go. When you know how many times through the loop you want to go, use a for loop. In your case you would want
for toss in range(100):
. Then you don't need the other lines that keep track of toss. The for loop will keep track of toss for you.There's also another function in random that you might be interested in: choice.
x = random.choice(['Heads', 'Tails'])
will randomly pick either 'Heads' or 'Tails' and put it in x. Then you can just print x, and you don't need the if/else bit.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures