Friday, 15 January 2010

random - Quater Toss Guessing Game Python -



random - Quater Toss Guessing Game Python -

i wanted create work reason cant tails side work keeps on showing 1. take note still new @ python.

i want create loop. lets don't number guessed on. if no (it starts game again) or yes (it gives them playing)

this have far.

import random print 'welcome heads or tails guessing game' print '' print 'lets toss quater in air. chances come heads or tails every time split even? 5 times or 5000 times. take ejucated guess.' raw_input ('what number be? ') tossquater, itsheads, itstails = 1,1,1 while tossquater < 5000: if random.randint(1,500) == 1: itsheads = itsheads + 1 itstails = itstails + 1 tossquater = tossquater + 1 if tossquater == 1300: print 'first 1,500 tosses. heads come ' + str(itsheads) + ' times.' ' tails came ' + str(itstails)+ ' times.' if tossquater == 1900: print 'second 2,000 tosses. heads come ' + str(itsheads) + ' times damm!.' ' tails came ' + str(itstails)+ ' times.' if tossquater == 3050: print 'third , final 1,500 tosses. heads come ' + str(itsheads) + ' times...' ' tails came ' + str(itstails)+ ' times...' print '' print 'out of 5 times or 5000 times. number of heads showed out be.' + str(itsheads) + ' times! ' ' tails showed ' + str(itstails) + ' times..' raw_input ('\n\ndid number take right one?')

you're incrementing itstails variable , printing out itstails variable. so, when print out itstails variable, shows 1 (because hasn't been incremented). code should like

itstails = itstails+1

apart that, logic seems flawed. have preferred next code:

import random while tossquater < 5000: if random.randint(1,2) == 1: itsheads = itsheads + 1 else: itstails = itstails + 1 tossquater = tossquater + 1

i setting status if 1, heads , if 2, tails. fair assumption, not realistic one, because randint method generate number based on inbuilt function.

python random

No comments:

Post a Comment