Python:猜拳游戲


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) #查看生成的隨機值

 代碼

輸出

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM