[Tutor] Flip a coin
Najam Us Saqib
ausnajm at yahoo.com.au
Tue Apr 9 13:50:45 CEST 2013
Hi,
This program is killing me, I have been working on it for last 3 hours, I have tried my best but can't make it work, please help me out.
The Problem:
Create a program that flips a coin 100 times and than tells you the number of tails and heads.
My code:
# Flip a coin
import random
flip_coin = 100
head = ""
tail = ""
n_head = 0
n_tail = 0
the_num = (raw_input("Press enter key to flip the coin!"))
#raw_input("Please Flip the Coin")
while flip_coin != 100:
flip_coin = random.randrange(100) +1
if flip_coin <= 50:
print "head"
else:
print "tail"
the_num = (raw_input("Press Enter to flip the coin"))
n_head += 1
n_tail += 1
print "The total numbers of heads are" ,n_head
print "The total numbers of tails are" ,n_tail
raw_input("\n\nPress the enter key to exit, thank you")
Thank you very much, looking forward to hear from you.
Regards,
Najam.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130409/64f13465/attachment.html>
More information about the Tutor
mailing list