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
4f610272
authored
Oct 27, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
25abb509
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
1 deletions
716.py
diy1.py
716.py
0 → 100644
View file @
4f610272
逻辑运算符
and
和,与,且
or
或
not
非,不
条件判断
单分支:
if
今天上课:
好好听讲
双分支:(两种情况)
if
今天是周末
:
休息
else
:
# 否则(今天不是周末)
上学
多分支:(两种以上情况)
if
今天是周一
:
吃
KFC
elif
今天是周二
:
吃麦当劳
elif
今天是周三
:
吃必胜客
...
(周四)
...
(周五)
...
(周六)
else
:
(今天是周日)
吃华莱士
换行符:
\
n
\ No newline at end of file
diy1.py
View file @
4f610272
player
=
input
(
"请出拳:石头/剪刀/布"
)
# 玩家出拳
import
random
# 导入随机数模块
player
=
input
(
"请出拳:"
)
print
(
"玩家出拳:"
+
player
)
print
(
"玩家出拳:"
+
player
)
list
=
[
"石头"
,
"剪刀"
,
"布"
]
computer
=
random
.
choice
(
list
)
# 随机抽取(选取)
print
(
"计算机出拳:"
+
computer
)
# QUAN
if
player
in
list
:
# 判断玩家出拳是否为石头、剪刀或者布
if
player
==
computer
:
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