import easygui
from easygui import *
import random
import sys
compscore = 0
playerscore = 0
for i in range(0,5):
def gamerules():
msgbox ('For this game you must choose one of the option to batle against your optonint')
def player_choice():
msg = ('Rock, Paper, Scissors')
title = ('Choose your action')
choices =['Rock','Paper','Scissors']
choice = choicebox(msg, title, choices)
if choice =='Rock':
msgbox('You chose Rock', image = 'sizzors_gif.gif')
elif choice == 'Paper':
msgbox('You chose Paper', image = 'paer_gif.gif')
elif choice == 'Scissors':
msgbox('You chose Scissors', image = 'source.gif')
return msgbox
def computer_choice():
msg = ('the computer choose')
title = ('computer turn')
computer_choice = [ 'Rock', 'Paper', 'Sizzors' ]
computer = (random.sample(computer_choice, 1))
compchoice = (computer)
choice = buttonbox(msg, title, compchoice)
if choice == 'Sizzors':
msgbox('computer choose rock:', image = 'source.gif')
sizzors = 'sizzors'
return sizzors
elif choice == 'Rock':
msgbox('computer choose sizzors :', image = 'sizzors_gif.gif')
rock = 'rock'
return rock
elif choice == 'Paper':
msgbox('computer choose paper :', image = 'paer_gif.gif')
paper = 'paper'
return paper
def roundwinner(player,computer, compwinner, playerwinner):
if player == 'rock' and computer == 'paper':
msgbox('you lost the point goes to the computer')
compwinner = compwinner + 1
elif computer == 'sizzors':
msgbox("You win!", "continue", image = 'Ghuman_winner.gif')
playerwinner = playerwinner + 1
else:
msgbox ('you and the computer tied no point is rewarded', "continue")
if player == "Paper" and computer == "Scissors":
msgbox ("You lose!", computer, "continue", player)
compwinner = compwinner + 1
elif computer == 'rock':
msgbox ("You win!", player, "continue", computer)
playerwinner = playerwinner + 1
if player == "Scissors":
if computer == "Rock":
msgbox ("You lose...", computer, "continue", player)
compwinner = compwinner + 1
else:
msgbox ("You win!", player, "continue", computer)
playerwinner = playerwinner + 1
move = player_choice()
computermove = computer_choice()
winner = roundwinner (move, computermove, compscore, playerscore )
Asked
Active
Viewed 37 times
0

roganjosh
- 12,594
- 4
- 29
- 46
-
2Why are you defining functions _within_ the `for` loop – roganjosh Nov 24 '19 at 19:43
1 Answers
0
You shouldn't put function definition into for
loop (because only the last one will remain); Instead, put those last lines in the for loop:
for i in range(5):
move = player_choice()
computermove = computer_choice()
winner = roundwinner (move, computermove, compscore, playerscore )
In addition, you don't need to specify 0
in for i in range(0, 5)
; for i in range(5)
will do the same.
Edit
def player_choice():
msg = ('Rock, Paper, Scissors')
title = ('Choose your action')
choices =['Rock','Paper','Scissors']
choice = choicebox(msg, title, choices)
if choice == 'Rock':
msgbox('You chose Rock', image='sizzors_gif.gif')
elif choice == 'Paper':
msgbox('You chose Paper', image='paer_gif.gif')
elif choice == 'Scissors':
msgbox('You chose Scissors', image='source.gif')
return choice

Community
- 1
- 1

Pedram Parsian
- 3,750
- 3
- 19
- 34
-
I did that and yet it still doesn't tell the user if it won or loss – Arham Ghuman Nov 24 '19 at 20:32
-
I haven't use `easygui` package very much, but I thing you should return `choice` at the end of your `player_choice` function. Check edit and let me know if there is any issues. – Pedram Parsian Nov 24 '19 at 20:39
-
-
What _exactly_ happens? Is there any error, Or there is just no output message? Also consider moving `roundwinner (move, computermove, compscore, playerscore)` inside the `for` loop. – Pedram Parsian Nov 24 '19 at 21:18
-