Home > other >  How to make this game runs 5 times and give out the score at the end
How to make this game runs 5 times and give out the score at the end

Time:01-21

import random 

user_play = input("Do you want to play a Game Theory Situation (Henry's Version)? ").lower()

if "yes" in user_play:
    name = input("Hi, and welcome to Henry's House! Tell me your name! ").capitalize()
    
    print(f"\n{name}, this is a simple game, you and your nemesis will win money if you beat me")
    
    print("""
    You and your nemesis are in 2 different rooms at Henry's House. 
    You can't communicate with anyone but Henry.""")
    
    print(f"""
    Henry: {name}, this is the case, it's pretty simple. You just have to decide
    if you want to pull the string or not. And here is the outcome.
    \n
    {name} \ Your nemesis\t\t Yes \t\t\t  No
    --------------\t --------------------------\t ---------------------------
    Yes\t\t\t Both get $50 each\t\t You get $10, your nemesis $100
    No \t\t\t You get $100, your nemesis $10 $0 for both
    """)
    
    board_game = [[3, 1], [5, 0]]
    
    dictionary_results = {"(Y, Y)": (board_game[0][0], board_game[0][0]),
                          "(Y, N)": (board_game[0][1], board_game[1][0]),
                          "(N, Y)": (board_game[1][0], board_game[0][1]),
                          "(N, N)": (board_game[1][1], board_game[1][1])}
    
    
    user_choose = input("""
    Do you want to pull the string?
    Select:
    - 'Y' is Yes
    - 'N' is No
    """).upper()
        
    nemesis_choose = random.randint(0,1)
    
    if user_choose == "Y" and nemesis_choose == 0:
        user_result = dictionary_results["(Y, Y)"][0]
        nemesis_result = dictionary_results["(Y, Y)"][1]
        print(f"""
    You do, and so does your nemesis!
    You earned {user_result} points.
    Your nemesis earned {nemesis_result}""")
    
    elif user_choose == "N" and nemesis_choose == 0:
        user_result = dictionary_results["(N, Y)"][0]
        nemesis_result = dictionary_results["(N, Y)"][1]
        print(f"""
    You don't, but your nemesis does :(
    You earned {user_result} points.
    Your nemesis earned {nemesis_result}""")

    elif user_choose == "Y" and nemesis_choose == 1:
        user_result = dictionary_results["(Y, N)"][0]
        nemesis_result = dictionary_results["(Y, N)"][1]
        print(f"""
    You do, but your nemesis doesn't want to :(
    You earned {user_result} points.
    Your nemesis earned {nemesis_result}""")

    elif user_choose == "N" and nemesis_choose == 1:
        user_result = dictionary_results["(N, N)"][0]
        nemesis_result = dictionary_results["(N, N)"][1]
        print(f"""
    You both chose not to pull!
    You earned {user_result} points.
    Your nemesis earned {nemesis_result}""")
    

if user_result > nemesis_result:
    print(f"""Congrats, you won!""")

elif user_result == nemesis_result:
    print(f"""Well we tie!""")

elif user_result <= nemesis_result:
    print(f"""Congrats to me, I beat you!""")

I am looking for a way to make this game runs 5 times and calculate the score of all the round at the end. Can anyone help me with it? I am new to python so I dont really know how to use for and whole loop

CodePudding user response:

Changes made:

(1) Initialize two new variables score_of_user,score_of_nemesis. storing/adding the scores they obtained at every iteration.

(2) Created a for loop which runs 5 times. take input from the user. if it wants to pull string or not.

(3) print(score_of_user,score_of_nemesis) you can print to know the scores till now of the user and nemesis.

Code:

import random 

user_play = input("Do you want to play a Game Theory Situation (Henry's Version)? ").lower()

if "yes" in user_play:
    name = input("Hi, and welcome to Henry's House! Tell me your name! ").capitalize()
    
    print(f"\n{name}, this is a simple game, you and your nemesis will win money if you beat me")
    
    print("""
    You and your nemesis are in 2 different rooms at Henry's House. 
    You can't communicate with anyone but Henry.""")
    
    print(f"""
    Henry: {name}, this is the case, it's pretty simple. You just have to decide
    if you want to pull the string or not. And here is the outcome.
    \n
    {name} \ Your nemesis\t\t Yes \t\t\t  No
    --------------\t --------------------------\t ---------------------------
    Yes\t\t\t Both get $50 each\t\t You get $10, your nemesis $100
    No \t\t\t You get $100, your nemesis $10 $0 for both
    """)
    
    board_game = [[3, 1], [5, 0]]
    
    dictionary_results = {"(Y, Y)": (board_game[0][0], board_game[0][0]),
                          "(Y, N)": (board_game[0][1], board_game[1][0]),
                          "(N, Y)": (board_game[1][0], board_game[0][1]),
                          "(N, N)": (board_game[1][1], board_game[1][1])}
    score_of_user=0
    score_of_nemesis=0
    
    for i in range(5):
        user_choose = input("""
        Do you want to pull the string?
        Select:
        - 'Y' is Yes
        - 'N' is No
        """).upper()
            
        nemesis_choose = random.randint(0,1)
        
        if user_choose == "Y" and nemesis_choose == 0:
            user_result = dictionary_results["(Y, Y)"][0]
            nemesis_result = dictionary_results["(Y, Y)"][1]
            print(f"""
        You do, and so does your nemesis!
        You earned {user_result} points.
        Your nemesis earned {nemesis_result}""")
        
        elif user_choose == "N" and nemesis_choose == 0:
            user_result = dictionary_results["(N, Y)"][0]
            nemesis_result = dictionary_results["(N, Y)"][1]
            print(f"""
        You don't, but your nemesis does :(
        You earned {user_result} points.
        Your nemesis earned {nemesis_result}""")
    
        elif user_choose == "Y" and nemesis_choose == 1:
            user_result = dictionary_results["(Y, N)"][0]
            nemesis_result = dictionary_results["(Y, N)"][1]
            print(f"""
        You do, but your nemesis doesn't want to :(
        You earned {user_result} points.
        Your nemesis earned {nemesis_result}""")
    
        elif user_choose == "N" and nemesis_choose == 1:
            user_result = dictionary_results["(N, N)"][0]
            nemesis_result = dictionary_results["(N, N)"][1]
            print(f"""
        You both chose not to pull!
        You earned {user_result} points.
        Your nemesis earned {nemesis_result}""")
        
        score_of_user =user_result
        score_of_nemesis =nemesis_result
        
        #print(score_of_user,score_of_nemesis) By printing You can see at every iteration what scores they both scored till now
    

if score_of_user > score_of_nemesis:
    print(f"""Congrats, you won!""")

elif score_of_user == score_of_nemesis:
    print(f"""Well we tie!""")

elif score_of_user <= score_of_nemesis:
    print(f"""Congrats to me, I beat you!""")

Output:

Do you want to play a Game Theory Situation (Henry's Version)? yes
Hi, and welcome to Henry's House! Tell me your name! Yash
Yash, this is a simple game, you and your nemesis will win money if you beat me

    You and your nemesis are in 2 different rooms at Henry's House. 
    You can't communicate with anyone but Henry.

    Henry: Yash, this is the case, it's pretty simple. You just have to decide
    if you want to pull the string or not. And here is the outcome.
    

    Yash \ Your nemesis      Yes              No
    --------------   --------------------------  ---------------------------
    Yes          Both get $50 each       You get $10, your nemesis $100
    No           You get $100, your nemesis $10 $0 for both
    

        Do you want to pull the string?
        Select:
        - 'Y' is Yes
        - 'N' is No
        N
        You both chose not to pull!
        You earned 0 points.
        Your nemesis earned 0

        Do you want to pull the string?
        Select:
        - 'Y' is Yes
        - 'N' is No
        Y
        You do, but your nemesis doesn't want to :(
        You earned 1 points.
        Your nemesis earned 5

        Do you want to pull the string?
        Select:
        - 'Y' is Yes
        - 'N' is No
        Y
        You do, and so does your nemesis!
        You earned 3 points.
        Your nemesis earned 3

        Do you want to pull the string?
        Select:
        - 'Y' is Yes
        - 'N' is No
        N
        You both chose not to pull!
        You earned 0 points.
        Your nemesis earned 0
Do you want to pull the string?
        Select:
        - 'Y' is Yes
        - 'N' is No
        Y
        You do, but your nemesis doesn't want to :(
        You earned 1 points.
        Your nemesis earned 5
Congrats to me, I beat you!
  • Related