Friday 15 May 2015

Rock, Paper, Scissors on Python - Can't get computer to play? -



Rock, Paper, Scissors on Python - Can't get computer to play? -

# programme generate random game of rock, paper, scissors # in player able win/lose against computer import sys import random print("*********************************") print("let't play rock, paper, scissors!") print("*********************************") def computer(): number = random.randint (0,2) if (computer == 0): computer = "rock"; elif (computer == 1): computer = "paper"; elif (computer == 2): computer = "scissors"; # need repeat 7 times player = input("enter 0 rock, 1 paper, 2 scissors: ") #determine winner if (player == computer): print("it's draw. nobody won round.") elif (player == "rock"): if (computer == "paper"): print("paper covers rock! computer wins round.") elif (player == "paper"): if (computer == "rock"): print("paper covers rock! win round.") elif (player == "rock"): if (computer == "scissors"): print("rock busts scissors! win round.") elif (player == "scissors"): if (computer == "rock"): print("rock busts scissors! computer wins round.") elif (player == "scissors"): if (computer == "paper"): print("scissors cutting paper! win round.") elif (player == "paper"): if (computer == "scissors"): print("scissors cutting paper! win round.") #show_winner

it seems can't computer play or show result such "paper covers rock," etc... help appreciated... module results in:

there's couple of issues computer function, , how you're calling it.

firstly, needs homecoming value it's chosen, not assign it's own name:

def computer(): number = random.randint (0,2) if (computer == 0): homecoming "rock"; elif (computer == 1): homecoming "paper"; elif (computer == 2): homecoming "scissors";

and when comparisons, need phone call function computer(), not compare it's name:

if (player == computer()):

notice () after computer?

finally, play 7 times, need wrap whole question/answer logic in kind of loop:

for effort in range(7): player = input("enter 0 rock, 1 paper, 2 scissors: ") ...

you seem accepting integer player (0, 1, or 2), computer function returning rock, paper, or scissors. need take 1 or other.

python

No comments:

Post a Comment