Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rock, Paper, Scissors Help
#1
I am trying to code a rock, paper, scissors game but am struggling with the final step. When I run the module, it does everything up to showing what the computer chose. However, it does not finish the code and display the result of the game. I am very new to python so any help is appreciated. Here is the code:
from random import randint

print ("Welcome to Rock, Paper, Scissors")
print ("Try to beat this program in a simple game of Rock, Paper, Scissors.")
player = input('Rock, paper, or scissors ')
if player == 'rock':
  player == 'r'
  
elif player == 'paper':
  player == 'p'
  
elif player == 'scissors':
  player == 's'
  
chosen = randint(1,3)

if chosen == 1 :
  computer = "rock"
  print ("computer chose rock")
elif chosen == 2 :
  computer = "paper"
  print ("computer chose paper")
else:
  computer = "scissors"
  print ("computer chose scissors")
  
def func(player, computer):
  if player == 's' and computer == "rock":
    return ("You lost!")
  elif player == 's' and computer == "paper":
    return "You win!"
  elif player == 's' and computer == "scissors":
    return "You tied!"
  elif player == 'r' and computer == "rock":
    return "You tied!"
  elif player == 'r' and computer == "paper":
    return "You lost!"
  elif player == 'r' and computer == "scissors":
    return "You win!"
  elif player == 'p' and computer == "rock":
    return "You win!"
  elif player == 'p' and computer == "paper":
    return "You tied!"
  elif player == 'p' and computer == "scissors":
    return "You lost!"
Reply
#2
You define a function, func, which contains the logic for determining who won, but you never call that function. At the bottom of your code, if you add the line print(func(player, computer)), it should do as you expect.

Also, I don't think this is doing what you think it does. Take a look at it, and see if you can figure out why:
if player == 'rock':
  player == 'r'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock Paper Scissors Project in Python ankitdixit 8 4,717 Feb-23-2024, 03:14 PM
Last Post: DPaul
  Trying to create a visual rock paper scissors game urmom33 1 976 Dec-03-2022, 09:12 PM
Last Post: deanhystad
  Rock paper scissors in python with "algorithm" Agat0 23 5,777 Mar-01-2022, 03:20 PM
Last Post: Agat0
  Problem restricting user input in my rock paper scissors game ashergreen 6 4,492 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  Odd behavior with Rock Paper Scissor game DustinKlent 2 1,886 Aug-27-2020, 03:55 PM
Last Post: DustinKlent
  Trying to implement Best of 3 logic in rock paper scissors game ShAhCh 5 3,265 May-11-2020, 04:31 PM
Last Post: ShAhCh
  Rock Paper Scissors with dictionaries ewgreht 2 3,823 May-01-2020, 03:19 PM
Last Post: deanhystad
  Rock, Paper, Scissors.. Help..hidden bug xxunknownxx 4 2,605 Mar-19-2020, 02:46 AM
Last Post: jefsummers
  Problem with Basic Rock Paper Scissors code BirinderSingh 3 2,382 Sep-13-2019, 03:28 PM
Last Post: ichabod801
  Rock Paper Scissors (Need help) Lukili 1 2,428 Jan-14-2018, 10:00 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020