Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So I just wanna ask that how to get score system between two def function ao if made a score system in first def function and I made a score of 150 how to continue score in second def function from 150 only I tried the global command but it didn't work pls give me solution Here's my code

def play():
    money=100
    print("you have been given 100 coins for free at start")
    money=money-25
    number=(input("What will you choose 7up , 7down , 7: "))
    if number=="7up":
        import random 
        print("the random generated number is:")
        gen=(random.randrange(1,12))
        print(gen)
        if gen > (7):
            print("the random generated number is greater than 7.")
            print("congratulation u got 50 coins")
            money=money+50
            print("Your current money is")
            return (money)
        elif gen < (7):
            print("the random generated number is not greater than 7.")
            print("congratulation u got nothing")
            print("Your current money is")
            return (money)
        elif gen == (7):
            print("the random generated number is 7.")
            print("congratulation u got nothing")
            print("Your current money is")
            return (money)
    if number=="7down":
        import random 
        print("the random generated number is:")
        gen=(random.randrange(1,12))
        print(gen)
        if gen > (7):
            print("the random generated number is greater than 7.")
            print("congratulation u got nothng")
            print("Your current money is")
            return (money)
        elif gen < (7):
            print("the random generated number is not greater than 7.")
            print("congratulation u got 50 coins")
            money=money+50
            print("Your current money is")
            return (money)
        elif gen == (7):
            print("the random generated number is 7.")
            print("congratulation u got nothing")
            print("Your current money is")
            return (money)
    if number == "7":
        import random 
        print("the random generated number is:")
        gen=(random.randrange(1,12))
        print(gen)
        if gen > (7):
            print("the random generated number is greater than 7.")
            print("congratulation u got nothng")
            print("Your current money is")
            return (money)
        elif gen < (7):
            print("the random generated number is not greater than 7.")
            print("congratulation u got nothng")
            print("Your current money is")
            return (money)
        elif gen == (7):
            print("the random generated number is 7.Wow lucky.")
            print("congratulation u got 100 coins")
            money=money+100
            print("Your current money is")
            return (money)
def playagain():
    Money= global money
    return (Money)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
177 views
Welcome To Ask or Share your Answers For Others

1 Answer

You would have to use the global keyword in the function where it is created and then use it in the other function, using your examples directly:

Execute the play() function first and then execute playagain()

def play():
    global money
    money=100
    print("you have been given 100 coins for free at start")
    money=money-25
    number=(input("What will you choose 7up , 7down , 7: "))
    if number=="7up":
        import random 
        print("the random generated number is:")
        gen=(random.randrange(1,12))
        print(gen)
        if gen > (7):
            print("the random generated number is greater than 7.")
            print("congratulation u got 50 coins")
            money=money+50
            print("Your current money is")
            return (money)
        elif gen < (7):
            print("the random generated number is not greater than 7.")
            print("congratulation u got nothing")
            print("Your current money is")
            return (money)
        elif gen == (7):
            print("the random generated number is 7.")
            print("congratulation u got nothing")
            print("Your current money is")
            return (money)
    if number=="7down":
        import random 
        print("the random generated number is:")
        gen=(random.randrange(1,12))
        print(gen)
        if gen > (7):
            print("the random generated number is greater than 7.")
            print("congratulation u got nothng")
            print("Your current money is")
            return (money)
        elif gen < (7):
            print("the random generated number is not greater than 7.")
            print("congratulation u got 50 coins")
            money=money+50
            print("Your current money is")
            return (money)
        elif gen == (7):
            print("the random generated number is 7.")
            print("congratulation u got nothing")
            print("Your current money is")
            return (money)
    if number == "7":
        import random 
        print("the random generated number is:")
        gen=(random.randrange(1,12))
        print(gen)
        if gen > (7):
            print("the random generated number is greater than 7.")
            print("congratulation u got nothng")
            print("Your current money is")
            return (money)
        elif gen < (7):
            print("the random generated number is not greater than 7.")
            print("congratulation u got nothng")
            print("Your current money is")
            return (money)
        elif gen == (7):
            print("the random generated number is 7.Wow lucky.")
            print("congratulation u got 100 coins")
            money=money+100
            print("Your current money is")
            return (money)
def playagain():
    Money= money
    return (Money)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...