import random #導入包 play = int(input("請輸入(石頭0 剪刀1 布2):")) #這里的int必須加上 i = random.randint(0,2) # 隨機生成 0.1.2 其中一個值,並賦值給i if (play == 0 and i == 2) or (play == 1 and i == 0) or (play == 2 and i == 1): print("輸了!") elif play == i: print("平!") else: print("贏了!") print(i) #查看生成的隨機值
代碼
輸出