Anonymous user
Rock-paper-scissors: Difference between revisions
→{{header|Python}}
Line 552:
=={{header|Python}}==
<lang python>#!/usr/bin/python
from random import
from
from
WHATBEATS = { 'paper' : 'scissors',
Line 563 ⟶ 562:
ORDER = ('rock', 'paper', 'scissors')
CHOICEFREQUENCY =
def probChoice(choices, probabilities):
prob_accumulator = 0
accumulator = []
for p in probabilities:
prob_accumulator +=
accumulator.append(prob_accumulator)
r =
bsct =
chc = choices[bsct]
return chc
def checkWinner(a, b):
return b
elif a ==
return a
Line 595 ⟶ 589:
def registerPlayerChoice(choice):
CHOICEFREQUENCY[choice] += 1▼
def getRandomChoice():
choices = CHOICEFREQUENCY.keys()
probabilities = CHOICEFREQUENCY.values()
Line 612 ⟶ 599:
while True:
if
continue
Line 622 ⟶ 609:
# Don't register the player choice until after the computer has made
# its choice.
registerPlayerChoice(
winner = checkWinner(
if winner == None:
|