+ 1

Can anyone shorten my ROCK PAPER SCISSOR Code and Please explain how you did it!

https://code.sololearn.com/cQTmPEh2bvck/?ref=app

23rd May 2020, 5:23 AM
ROHIT PRADHAN
ROHIT PRADHAN - avatar
2 Respostas
+ 3
# you might want to optimize it a bit, not having to check for every possible combination: from random import choice as c h = 'rock', 'paper', 'scissors' # possible hands w = {h[0]: h[2], h[1]: h[0], h[2]: h[1]} # what beats which while True: p = input('rock, paper, scissors? ').lower() # always bring to lowercase if p not in h: break # if entered anything else - quit r = c(h) # computer chooses print('Computer chooses', r) if p == r: print('Tie!') elif w[p] == r: print(p, 'beats', r, '- YOU WIN!') else: print(r, 'beats', p, '- YOU LOSE')
23rd May 2020, 6:52 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar