rio wrote:
> i too am a newbie to programming (except BASIC over 20 years ago!).
> randrange() didnt seem to be in the random module (pyth2.4.2)
Sure it is, check your spelling and make sure you call it random.randrange():
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on w
i too am a newbie to programming (except BASIC over 20 years ago!).
randrange() didnt seem to be in the random module (pyth2.4.2)
random() IS but it doesn;t seem to take arguments. it returns a float
between 0.0 and 0., so random.random()*2 means half will be
(0.0-0.9) & half (1.0-1.9
Hello,I see two things can be changed a little bit.1. redundant: while, if2. print style at the last statement.see below:#Coin Toss Game#Zameer Manjiimport randomprint "This game will simulate 100 coin tosses and then tell you the
number of head's and tails"tosses = 0heads = 0tails = 0while tosses<
At 02:36 PM 11/1/2005, Zameer Manji wrote:
>Ok after looking at everyones replies my program looks like this:
>
>#Coin Toss Game
>#Zameer Manji
>import random
>
>print "This game will simulate 100 coin tosses and then tell you the
>number of head's and tails"
>
>tosses = 0
>heads = 0
>tails = 0
>
>
Ok after looking at everyones replies my program looks like this:
#Coin Toss Game
#Zameer Manji
import random
print "This game will simulate 100 coin tosses and then tell you the
number of head's and tails"
tosses = 0
heads = 0
tails = 0
while tosses<100:
if tosses<100:
coin = rando
22:10:34 -0500
> From: "R. Alan Monroe" <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] while/if/elif/else loops
> To: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=us-ascii
>
>
> > while tosses = 100<0:
>
> #Coin Toss Game
>
> print "This game will simulate 100 coin tosses and then tell you the
> number of head's and tails"
>
> import random
>
> tosses = 0
> heads = 0
> tails = 0
>
> while tosses = 100<0:
>coin = randrange(1)
>tosses +=1
>if coin == 0:
> heads +=1
> prin
> import random
>
>
> while tosses = 100<0:
> coin = randrange(1)
You need to preped random:
coin = random.randrange(1)
Otherwise it looks OKAlthough
> tosses +=1
> if coin == 0:
> heads +=1
> print "Heads"
You might want to output the count too
print heads, " heads"
> while tosses = 100<0:
I didn't run the program, but this immediately caught my eye as
looking kind of suspect. Was it a typo? Most programs usually
have a need for comparisons of equal, or greater/less, but it's really
rare to need both combined in one statement...
Also if you really _do_ want
Let's comment something:1. If you have error please show us your error message.2. When you code python be aware of indention, be persistent for example use tab space 4.3. import should be on the top of your code.
4. to choose random between integer 1 or 0 use randint(0,1)5. your last code use Print
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512
I'm new to programming and python. I've have recently been experimenting
with while/if/elif/else loops and I've created a simple number guessing
game. Now I want to create a coin tossing game, but I don't know how to
structure it in python. The code
11 matches
Mail list logo