Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson2-1-1_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
7952e7d8
authored
Aug 10, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
913aa56a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
280 additions
and
3 deletions
1.py
diy1.py
1.py
0 → 100644
View file @
7952e7d8
import
random
a
=
input
(
"请出拳(石头/剪刀/布):"
)
b
=
[
"剪刀"
,
"石头"
,
"布"
]
# 定义赢的列表
win_list
=
[[
"石头"
,
"剪刀"
],
[
"剪刀"
,
"布"
],
[
"布"
,
"石头"
]]
# 计算机随机选择出拳
mac
=
random
.
choice
(
b
)
print
(
"你出拳:"
,
a
)
print
(
"计算机出拳:"
,
mac
)
if
a
in
b
:
if
a
==
mac
:
print
(
"平局"
)
elif
[
a
,
mac
]
in
win_list
:
# 如果在赢的列表中,代表你赢了,主要你和计算机的顺序要和赢的列表一样
print
(
"恭喜,你赢了"
)
else
:
print
(
"很遗憾,你输了"
)
else
:
print
(
"输入错误"
)
每次出拳一次要运行一次,很麻烦,要让程序一直运行
在程序中加个
while
条件就解决啦
import
random
while
True
:
a
=
input
(
"请出拳(石头/剪刀/布):"
)
b
=
[
"剪刀"
,
"石头"
,
"布"
]
# 定义赢的列表
win_list
=
[[
"石头"
,
"剪刀"
],
[
"剪刀"
,
"布"
],
[
"布"
,
"石头"
]]
# 计算机随机选择出拳
mac
=
random
.
choice
(
b
)
print
(
"你出拳:"
,
a
)
print
(
"计算机出拳:"
,
mac
)
if
a
in
b
:
if
a
==
mac
:
print
(
"平局"
)
elif
[
a
,
mac
]
in
win_list
:
# 如果在赢的列表中,代表你赢了,主要你和计算机的顺序要和赢的列表一样
print
(
"恭喜,你赢了"
)
else
:
print
(
"很遗憾,你输了"
)
else
:
print
(
"输入错误"
)
长期玩游戏不利于身心健康,玩游戏要有度
那就默认游戏一开始有三次机会吧,每玩一次减掉一次机会,如果赢了就增加一次机会
import
random
count
=
3
while
count
:
a
=
input
(
"请出拳(石头/剪刀/布):"
)
b
=
[
"剪刀"
,
"石头"
,
"布"
]
# 定义赢的列表
win_list
=
[[
"石头"
,
"剪刀"
],
[
"剪刀"
,
"布"
],
[
"布"
,
"石头"
]]
# 计算机随机选择出拳
mac
=
random
.
choice
(
b
)
print
(
"你出拳:"
,
a
)
print
(
"计算机出拳:"
,
mac
)
if
a
in
b
:
count
-=
1
if
a
==
mac
:
print
(
"平局"
)
elif
[
a
,
mac
]
in
win_list
:
# 如果在赢的列表中,代表你赢了,主要你和计算机的顺序要和赢的列表一样
print
(
"恭喜,你赢了"
)
count
+=
1
else
:
print
(
"很遗憾,你输了"
)
else
:
print
(
"输入错误"
)
print
(
"你还剩余机会"
,
count
)
免费玩了这么多次,要给项目创造一点收益啊
当游戏剩余机会
0
时,用户可选择充值继续玩,
1
块钱等于三次机会,输入字符串或者输入的不是
1
,
5
,
10
时,退出程序
import
random
count
=
3
while
count
:
a
=
input
(
"请出拳(石头/剪刀/布):"
)
b
=
[
"剪刀"
,
"石头"
,
"布"
]
win_list
=
[[
"石头"
,
"剪刀"
],
[
"剪刀"
,
"布"
],
[
"布"
,
"石头"
]]
mac
=
random
.
choice
(
b
)
print
(
"你出拳:"
,
a
)
print
(
"计算机出拳:"
,
mac
)
if
a
in
b
:
count
-=
1
if
a
==
mac
:
print
(
"平局"
)
elif
[
a
,
mac
]
in
win_list
:
print
(
"恭喜,你赢了"
)
count
+=
1
else
:
print
(
"很遗憾,你输了"
)
else
:
print
(
"输入错误"
)
print
(
"你还剩余机会"
,
count
)
if
count
==
0
:
print
(
"机会用完啦,充值可以继续玩哦,充值金额分别为1,5,10元,一元可增加三次机会。"
)
a
=
input
(
"请选择充值金额:"
)
try
:
a
=
int
(
a
)
if
a
==
1
or
a
==
5
or
a
==
10
:
count
=
a
else
:
print
(
"请输入1,5,10"
)
except
:
print
(
"请输入正确的金额"
)
输入字符串或者输入不是
1
,
5
,
10
可以继续输入或者选择
q
退出
import
random
count
=
3
while
count
:
a
=
input
(
"请出拳(石头/剪刀/布):"
)
b
=
[
"剪刀"
,
"石头"
,
"布"
]
win_list
=
[[
"石头"
,
"剪刀"
],
[
"剪刀"
,
"布"
],
[
"布"
,
"石头"
]]
mac
=
random
.
choice
(
b
)
print
(
"你出拳:"
,
a
)
print
(
"计算机出拳:"
,
mac
)
if
a
in
b
:
count
-=
1
if
a
==
mac
:
print
(
"平局"
)
elif
[
a
,
mac
]
in
win_list
:
print
(
"恭喜,你赢了"
)
count
+=
1
else
:
print
(
"很遗憾,你输了"
)
else
:
print
(
"输入错误"
)
print
(
"你还剩余机会"
,
count
)
if
count
==
0
:
print
(
"机会用完啦,充值可以继续玩哦,充值金额分别为1,5,10元,一元可增加三次机会。"
)
while
True
:
a
=
input
(
"请选择充值金额或者输入Q退出:"
)
if
a
==
'Q'
:
exit
()
try
:
a
=
int
(
a
)
if
a
==
1
or
a
==
5
or
a
==
10
:
count
=
a
else
:
print
(
"请输入1,5,10"
)
except
:
print
(
"请输入正确的金额"
)
————————————————
版权声明:本文为
CSDN
博主「回忆的眼泪」的原创文章,遵循
CC
4.0
BY
-
SA
版权协议,转载请附上原文出处链接及本声明。
原文链接:
https
:
//
blog
.
csdn
.
net
/
weixin_29471541
/
article
/
details
/
113503712
\ No newline at end of file
diy1.py
View file @
7952e7d8
# 我们都爱夸夸夸
name
=
input
(
"请输入你的name"
)
print
(
name
+
"你小狗"
)
a
=
input
(
"出什么:"
)
print
(
"我出:"
+
a
)
\ 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