Welcome to Dream.In.Code
Become an Expert!

Join 149,510 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,363 people online right now. Registration is fast and FREE... Join Now!




Basketball Code

 
Reply to this topicStart new topic

Basketball Code, Horse Program

Davidshor
16 Jul, 2007 - 11:20 PM
Post #1

New D.I.C Head
*

Joined: 16 Jul, 2007
Posts: 1


My Contributions
Players A, B take turns making a shot. If the player fails to make a shot while the player before him does make a shot, he gets a point. If he misses the shot while the player before him also misses, nothing happens, and the next player shoots.

When someone accrues five points, they are eliminated from the game. The remaining player is the winner.

I want code that takes two variables(The probability a that A will make a shot and the probability b that B will make a shot) and then simulates a game. If player A wins, output 0, if player b wins, outputs 1.

I am very bad at programing, so forgive what I have tried to do so far.
CODE
def F(a,b):
    q=0
    w=0
    i=0
    u=0
    while q<5 and w<5:
        if random.random()<a:
            i=1
            u=u+1
        else:
            i=0
            u=u+1
        if random.random()>b:
            u=u+1
            if i==1:
                if u%2==1:
                    w=w+1
                else:
                    q=q+1
        else:
            u=u+1
    if q<5:
        return 0
    if w<5:
        return 1

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 07:34PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month