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
f4ff57ee
authored
Apr 23, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
32582699
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
diy1.py
diy1.py
View file @
f4ff57ee
import
random
# 导入random模块
# 玩家出拳
a
=
input
(
"请出拳(石头/剪刀/布):"
)
print
(
"玩家出:"
+
a
)
\ No newline at end of file
player
=
input
(
"玩家出拳(石头/剪刀/布):"
)
# 输入的内容
print
(
"玩家出:"
+
player
)
# 打印出:玩家出:+输入的内容
# 计算机随机出拳
list
=
[
"石头"
,
"剪刀"
,
"布"
]
# 建立列表
computer
=
random
.
choice
(
list
)
# 在列表中随机抽取一个元素
pint
(
"计算机出拳:"
+
computer
)
# 显示结果
# 完善输入错误时的情况
if
play
in
list
:
if
player
==
computer
:
# if条件判断,如果玩家出=计算机出拳
print
(
"平局"
)
# 打印出,平局
elif
(
player
==
"石头"
and
computer
==
"剪刀"
)
or
(
player
==
"剪刀"
and
computer
==
"布"
)
or
(
player
==
"布"
and
computer
==
"石头"
):
print
(
"恭喜,你赢了"
)
# 打印出,你赢了 ^如果不平局,将继续判断以上内容
else
:
# 否则
print
(
"很遗憾,你输了"
)
# 打印出,你输了
else
:
# 否则
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