Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson2-2_DIY1
This project
Loading...
Sign in
Toggle navigation
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
Commit
32ba46f4
authored
Mar 03, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
91ed362a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
diy1.py
diy1.py
View file @
32ba46f4
# 玩家出拳
# 玩家出拳
player
=
input
(
"请出拳(石头/剪刀/布)
:
"
)
# 输入的内容
player
=
input
(
"请出拳(石头/剪刀/布)
:
"
)
# 输入的内容
print
(
"玩家出
: "
+
player
)
# 打印出:玩家出:+输入的内容
print
(
"玩家出
拳:"
+
player
)
# 打印出:玩家出:+输入的内容
# 计算机出拳
# 计算机出拳
import
random
# 导入random模块
import
random
# 导入random模块
list
=
[
"石头"
,
"剪刀"
,
"布"
]
# 建立列表
list
=
[
"石头"
,
"剪刀"
,
"布"
]
# 建立列表
computer
=
random
.
choice
(
list
)
# 在列表中抽取随机元素
computer
=
random
.
choice
(
list
)
# 在列表中抽取随机元素
p
int
(
"计算机出拳:"
+
computer
)
p
rint
(
"计算机出拳:"
+
computer
)
# 显示结果
# 显示结果
if
player
==
computer
# if条件判断,如果玩家出=计算机出
if
player
==
computer
:
# if条件判断,如果玩家出=计算机出
print
(
"平局"
)
# 打印出,平局
print
(
"平局"
)
# 打印出,平局
elif
(
player
==
"石头"
and
computer
==
"剪刀"
)
or
(
player
==
"剪刀"
and
computer
==
"布"
)
or
(
player
==
"石头"
and
computer
==
"布"
):
# 如果不平局,继续判断这段条件
elif
(
player
==
"石头"
and
computer
==
"剪刀"
)
or
(
player
==
"剪刀"
and
computer
==
"布"
)
or
(
player
==
"石头"
and
computer
==
"布"
):
# 如果不平局,继续判断这段条件
print
(
"你赢了"
)
# 打印出,你赢了
print
(
"你赢了"
)
# 打印出,你赢了
else
:
# 否则
else
:
# 否则
print
(
"你输了"
)
# 打印出,你输了
print
(
"你输了"
)
# 打印出,你输了
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment