lundi 17 juillet 2023

How do I assign a percent chance to a value in python? [duplicate]

I am writing a program for a rock paper scissors game. Currently I am using the random command for the computer to choose between the three options. I want to add a fourth option, but instead of it being an even chance between the four I'd like to be a 1% chance to get the fourth option. Is there a way to assign a specific % chance to these options?

Here is my code currently:

import random
user_action = input("Choose: Rock, Paper, Scissors")
possible_actions = ["Rock", "Paper", "Scissors"]
computer_action = random.choice(possible_actions)
print(f"\n You Chose {user_action}, Computer Chose {computer_action}.\n")

if user_action == computer_action:
    print(f"Both player chose {user_action}. You Tied!")
elif user_action == "Rock":
    if computer_action == "Scissors":
        print("Rock smashes scissors! You win!")
    else:
        print("Paper covers rock, you lose!")
elif user_action == "Paper":
    if computer_action == "Rock":
        print("Paper covers rock, You Win!")
    else:
        print("Scissors cut the paper into shreds! You lose!")
elif user_action == "Scissors":
    if computer_action == "Paper":
        print("Scissors cut the paper into shreds! You win!")
    else:
        print("Rock smashes scissors! You lose!")



Aucun commentaire:

Enregistrer un commentaire