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
26a2f50c
authored
Mar 12, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
69c75b80
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
6 deletions
diy1.py
diy1.py
View file @
26a2f50c
import
random
player
=
input
(
"请出拳:石头/剪刀/布"
)
player
=
input
(
"请出拳:石头/剪刀/布"
)
print
(
"玩家出拳:"
+
player
)
print
(
"玩家出拳:"
+
player
)
import
random
list
[
"石头"
,
"剪刀"
,
"布"
]
list
[
"石头"
,
"剪刀"
,
"布"
]
computer
=
random
.
choice
(
list
)
computer
=
random
.
choice
(
list
)
print
(
"电脑玩家出拳:"
+
computer
)
print
(
"电脑玩家出拳:"
+
computer
)
if
player
==
computer
:
print
(
"平局"
)
if
player
in
list
:
elif
(
player
==
"石头"
and
computer
==
"布"
)
or
(
player
==
"布"
and
computer
==
"剪刀"
)
or
(
player
==
"剪刀"
and
computer
==
"石头"
):
if
player
==
computer
:
print
(
"失败"
)
print
(
"平局"
)
elif
(
player
==
"石头"
and
computer
==
"布"
)
or
(
player
==
"布"
and
computer
==
"剪刀"
)
or
(
player
==
"剪刀"
and
computer
==
"石头"
):
print
(
"失败"
)
else
:
print
(
"胜利"
)
else
:
else
:
print
(
"胜利"
)
print
(
"输入错误"
)
三种或三种以上的判断用
if
。。。
elif
。。。
else
elif
是
else
。。。
if
的缩写
意思否则如果
当用到随机功能时,
random
需要导入
random
模块
import
random
其中
choice
()是在列表中随机抽取一个元素
random
.
choice
示例:
list
=
[
"a"
,
"b"
,
"c"
,
"d"
]
random
.
choice
(
list
)
功能
列表中随机选一项
知识要勤于复习
才是自己的
print
(
"hello"
+
"world!"
)
"+"
连接字符串作用
如果有数值需要转化成字符串才能连接
使用
turtle
模块应先用
import
导入
import
turtle
再进行画图
创建画笔
pen
=
turtle
.
Pen
()
P
为大写
使用画笔的功能时,我们要在前面加上
pen
中间用点连接
例如:
pen
.
forward
()
pen
.
left
()
print
(
"你好"
)
功能
在控制台输出内容
input
(
"你叫什么"
)
功能
在控制台输入内容
在英文为
输入的意思
就是请输入指令
查看任何导入模块
ctrl
+
鼠标左键
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