#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    For school: Need help please


    We have an imaginary pile of 16 beans. I'm supposed to create two functions to represent two players in a game. Each function will be called upon by the main program to take their turn (take beans out of the pile). So far my main program is calling the functions, but it's not keeping up with the total number of beans after each player takes some out. It keeps going back to 16 so my program never finishes. Is my naming off? I'm very very very new to this and taking the course so I can get my degree in desktop support so please be patient with me, trust me I'm trying as hard as I can. Here is what I have so far. I just need it to keep the value after each turn instead of going back to 16.

    def player_one(beans):
    total= beans - 1
    print("Player one takes 1 bean. Beans left:")
    return total

    def player_two(beans):
    total = beans - 3
    print("Player two takes 3 beans. Beans left:")
    return total

    beans = 16

    while beans > 0:

    print(player_one(beans))
    if beans == 0:
    print("Player one loses.")

    print(player_two(beans))
    if beans == 0:
    print("Player two loses.")

    else:
    print("Game Over")
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,931
    Rep Power
    481
    Code:
    beans = 16
    
    while beans > 0:
    
        beans = player_one(beans)
        print(beans)
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0
    I love you so much right now. You don't know how much I appreciate what you just showed me! I plugged that into my code and voila player two loses! Thank you so very very much, I can finally stop crying!

IMN logo majestic logo threadwatch logo seochat tools logo