“Exemple de jeu Python” Réponses codées

Exemple de jeu Python


import random
import time

computerwins = 0
playerwins = 0
ties = 0
end = 0

while True:

    choices = ["rock",
               "paper",
               "scissors"]

    userChoice = raw_input("Rock, Paper, Scissors, or End")

    computerChoice = (random.choice(choices))
    print(computerChoice)

    if userChoice == computerChoice:
        time.sleep(0.5)
        print("Tie!\n")
        ties += 1
        end += 1

    elif userChoice == "rock":
        if computerChoice == "paper":
            time.sleep(0.5)
            print("Computer Win!\n")
            computerwins +=1
            end += 1

        else:
            time.sleep(0.5)
            print("Player win!\n")
            playerwins += 1
            end += 1

    elif userChoice == "paper":
        if computerChoice == "rock":
            time.sleep(0.5)
            print("Player win!\n")
            playerwins += 1
            end += 1

        else:
            time.sleep(0.5)
            print("Computer win!\n")
            computerwins += 1
            end += 1

    elif userChoice == "scissors":
        if computerChoice == "rock":
            time.sleep(0.5)
            print("Computer win!\n")
            computerwins += 1
            end += 1

        else:
            time.sleep(0.5)
            print("Player win!\n")
            playerwins += 1
            end += 1

    elif userChoice == "end":
            choices.append("end")
            print("\nGreat game!\n")
            print("Total score for computer: ", computerwins, "wins!")
            print("Total score for player: ", playerwins, "wins!")
            print("Total ties: ", ties, "ties!")
            time.sleep(2)
            break
ayaan

Comment faire un jeu en Python

#modules required - time and random
#Game 1
#Password game
import time
import random

Password = ['1', '2', 'a', 'G', '5', '89']

answer = input('Guess the password')
print(random.choice(Password)+' is the password')
Outstanding Ox

Réponses similaires à “Exemple de jeu Python”

Questions similaires à “Exemple de jeu Python”

Plus de réponses similaires à “Exemple de jeu Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code