Here is the psuedo code I was supposed to create in python:
PlayerOneScore ← 0
PlayerTwoScore ← 0
OUTPUT "How many games?"
INPUT NoOfGamesInMatch
FOR NoOfGamesPlayed ← 1 TO NoOfGamesInMatch Do
OUTPUT "Did Player One win the game (enter Y or N)?"
INPUT PlayerOneWinsGame
IF PlayerOneWinsGame = 'Y'
THEN PlayerOneScore ← PlayerOneScore + 1
ELSE PlayerTwoScore ← PlayerTwoScore + 1
ENDIF
ENDFOR
OUTPUT PlayerOneScore
OUTPUT PlayerTwoScore
Here is what I created in python and its not working and I don't understand why?
PlayerOneScore = 0
PlayerTwoSCore = 0
NoOfGamesInMatch = input("How Many games?")
for NoOfGamesPlayed != NoOfGamesInMatch:
PlayerOneWinsGame = input(" Did Player on win the game(Enter y or N?)")
if PlayerOneWinsGame == "Y":
PlayerOneScore = PlayerOneScore + 1
else:
PlayerTwoScore = PlayerTwoScore = 1
print("Player one Score is" + str(PlayerOneScore))
print("Player Two Score is" + str(PlayerTwoScore))
I tried the in range part, and I got this error when I input one when the program input how many games.
for NoOfGamesPlayed in range(NoOfGamesInMatch):
TypeError: 'str' object cannot be interpreted as an integer
for NoOfGamesPlayed != NoOfGamesInMatchthis have no sense.for NoOfGamesPlayed != NoOfGamesInMatchis not valid Python code. You tagged this withwhile-loop, perhaps you meant to usewhilethere? If so, how do you increment your loop counter?