Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

bellcode / lesson2-5_DIY1

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • lesson2-5_DIY1
  • diy1.py
Find file
BlameHistoryPermalink
  • BellCodeEditor's avatar
    save project · ec442405
    BellCodeEditor committed 2 years ago
    ec442405
diy1.py 957 Bytes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#玩家出拳
player=input("出拳:石头/剪刀/布")    #玩家出拳,并用变量player存储答案
print("玩家出拳:"+player)          #打印玩家出拳答案
import random                      #导入random模块
#计算机随机出拳
list=["石头","剪刀","布"]           #创建列表,存储三个参数
computer=random.choice(list)       #在列表中随机抽取一个元素存入变量computer中
print(computer)                    #打印计算机出拳答案
#结果判断
if player==computer:               #如果玩家出拳结果等于计算机出拳结果
    print (平局)                    #打印 平局
#添加三个条件判断
elif (player=="石头" and computer=="剪刀") or (player=="剪刀" and computer=="布") or (player=="布" and computer=="石头"):
    print("You are win")  #打印玩家赢
else:                     #否则:条件都不成立
    print("You are a loser") #打印玩家输