+ 1

Error

What's wrong with this code? from random import * userScore = 0 compScore = 0 confirm = True def addUser(): userScore += 1 def addComp(): compScore += 1 def gameError(): print ("Error. Input rock, paper or scissor") def computerGen(): return random.choice(["rock", "paper", "scissor"]) def isValid(text): if (text == "rock"): return True if (text == "paper"): return True if (text == "scissor"): return True else: return False def checkWin(user, comp): if ((user == "rock") and (comp == "scissor")): return True if ((user == "paper") and (comp == "rock")): return True if ((user == "scissor") and (comp == "paper")): return True return False def startGame(gameInput): comp = computerGen() if (user == comp): print ("Tie") else: if (checkWin(user, comp)): print ("Won") else: print ("Lose") while (confirm): user = input("Input rock, paper or scissor.").lower() if (user == "quit"): print ("Good game.") confirm = False break else: if (isValid(user)): startGame(user) else: gameError()

8th May 2017, 4:46 AM
Tom Tommy
Tom Tommy - avatar
2 Antworten
+ 4
Line 24 and 26 replace those two with elif instead of if.
8th May 2017, 5:00 AM
Complex
Complex - avatar
+ 1
if you change random.choice to choice in computerGen, does it help ?
8th May 2017, 9:22 PM
Amaras A
Amaras A - avatar