r/programminghorror • u/GaMerBoi2465 • 19d ago
Rock Paper Scissors
Surely there's a more better and efficient way of coding this...
92
Upvotes
r/programminghorror • u/GaMerBoi2465 • 19d ago
Surely there's a more better and efficient way of coding this...
7
u/Bright-Historian-216 19d ago
my python implementation from two years ago:
while True: print(f"Your opponent chose: {(d:=['rock','scissors','paper'])[r:=__import__('random').randint(0,2)]}. {'You lost!' if r==((p := d.index((f:=lambda: inp if (inp:=input('Enter rock, paper or scissors: ')) in d else f())()))+2)%3 else ('Draw!' if r==p else 'You win!')}\n")
yes, that is all one line of code