[PYTHON] Janken

script.py import utils

Chargez le module aléatoire

import random

print ('Start Janken') player_name = input ('Veuillez saisir un nom:') print ('Que voulez-vous imprimer? (0: Goo, 1: Choki, 2: Par)') player_hand = int (input ('Veuillez saisir des nombres:'))

if utils.validate(player_hand): Utilisez # randint pour obtenir un nombre de 0 à 2 et attribuez-le à la variable computer_hand computer_hand = random.randint(0,2)

if player_name == '':
    utils.print_hand(player_hand)
else:
    utils.print_hand(player_hand, player_name)

utils.print_hand (main_ordinateur, 'ordinateur')

result = utils.judge(player_hand, computer_hand)

print ('Le résultat était' + résultat + 'était') else: print ('Entrez le numéro correct')


utils.py def validate(hand): if hand < 0 or hand > 2: return False return True

def print_hand (main, nom = 'invité'): mains = ['goo', 'choki', 'par'] print (nom + 'émis' + mains [main] + ')

def judge(player, computer): if player == computer: retour 'draw' elif player == 0 and computer == 1: retour'win ' elif player == 1 and computer == 2: retour'win ' elif player == 2 and computer == 0: retour'win ' else: retour 'perdant'

Recommended Posts

Janken
Janken en Ruby