Python Forum
My code won't say Player wins or computer wins. No errors. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: My code won't say Player wins or computer wins. No errors. (/thread-35688.html)



My code won't say Player wins or computer wins. No errors. - its_a_meLuigi64 - Dec-01-2021

#!/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!!')



RE: My code won't say Player wins or computer wins. No errors. - Yoriz - Dec-01-2021

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.


RE: My code won't say Player wins or computer wins. No errors. - its_a_meLuigi64 - Dec-01-2021

Thank You!