python3.8 + only
print("a|b|c"*-~-((a:=input("a:Par\nb:Choki\nc:Goo\n"))in"abc")or"Draw"*((b:=__import__("random").choice("abc"))==a)or"You "+"lwoisne"[b+a in"abbcca"::2],f"\nyou:{a} pc:{b}")
185 bytes
First of all, maybe it can be shorter ...
Well to make it easier to understand
import random
a = input("a:Par\nb:Choki\nc:Goo")
b = random.choice("abc")
if -~-(a in "abc"):
print("a|b|c")
elif a == b:
print("Draw")
else:
print("win" if b+a in "abbcca" else "lose")
print(f"you:{a} pc:{b}")
Is it like this? I change it a little.
Probably the most mysterious thing is -~-
. This means that ~-is -1 (-~ is +) and it is further-. If ʻa in "abc" `is True (because bool is a subclass of int), it is -1 and becomes-, so it becomes -0, that is, 0, and if False, it becomes 1. In short, it means that not 〇〇 is written short. (In the case of the bottom, it becomes longer, but in the case of the top, it becomes shorter)
Then, is it b + a in" abbcca "
? This is a judgment of winning or losing. It may be easier to understand if you separate it from ab / bc / ca.
__import__
is a function that imports the module specified by the argument and returns the object. (Isn't it correct?) Well, see here for details.
Is it something like ~~~ * ~~~ or ~~~ * ~~~ or ...
? This uses the fact that the empty string becomes False in python. I usually feel like using it like str * bool
.
Feel free to comment if you have any questions, if you can write shorter, or if you can write more clearly: smile:
Recommended Posts