Python Forum
My code won't say Player wins or computer wins. No errors.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My code won't say Player wins or computer wins. No errors.
#1
#!/bin/python3

from random import randint

player = input('Paper(p), Scissors(s), or Rock(r).')

print(player, 'vs', end= ' ')
chosen = randint(1,3)
#print(chosen)

if chosen == 1:
  computer = 'r'
  
elif chosen == 2:
  computer = 'p'

else:
  computer = 's'

print(computer)

if player ==chosen:
  print('DRAW!!!!')

elif player == 'R' and computer == 'S':
  print("Player wins!!")

elif player == 'R' and computer == 'P':
  print('Computer wins!!')
  
elif player == 'P' and computer == 'R':
  print("Player wins!!")
  
elif player == 'P' and computer == 'S':
  print('Computer wins!!')
  
elif player == 'S' and computer == 'P':
  print("Player wins!!")
  
elif player == 'S' and computer == 'R':
  print('Computer wins!!')
Yoriz write Dec-01-2021, 04:38 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
The computer chooses lower case letters, the input could be either lower of uppercase.
The comparisons done are uppercase.

Note:
The string method upper or lower could be used to change the case.
random choice could be used to choose a string directly.
Reply
#3
Thank You!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Are there errors in the code for my coin toss systems? Matlibplot is too perfect . Coolkat 0 369 Nov-13-2023, 11:54 AM
Last Post: Coolkat
  Rmarkdown opened by python code - errors Rav013 0 2,085 Apr-27-2021, 03:13 PM
Last Post: Rav013
  [split] Kera Getting errors when following code example Image classification from scratch hobbyist 3 4,606 Apr-13-2021, 01:26 PM
Last Post: amirian
  Assign 1 player to the computer ironic100 2 2,412 Aug-14-2020, 01:51 PM
Last Post: GOTO10
  2 errors in code numbnumb54 2 2,013 Jul-24-2020, 02:28 PM
Last Post: Marbelous
  Code errors rhyjom 0 1,458 Jun-21-2020, 04:50 PM
Last Post: rhyjom
  Errors in code coolcassie 2 2,111 Dec-03-2019, 12:10 AM
Last Post: coolcassie
  Errors trying to run code ziggyztz 3 3,653 Nov-03-2019, 04:24 AM
Last Post: newbieAuggie2019
  errors in code sylvie1987100 3 2,300 Sep-11-2019, 12:54 PM
Last Post: sylvie1987100
  Decorator toy code throws syntax errors kevinxhi 3 3,556 Sep-04-2017, 03:01 AM
Last Post: kevinxhi

Forum Jump:

User Panel Messages

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