Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson2-4-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
6b631fcf
authored
Mar 12, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
9397f8e6
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
11 deletions
c4.py
diy1.py
jk.py
wuhan.txt
c4.py
0 → 100644
View file @
6b631fcf
import
random
all
=
[
'石头'
,
'剪刀'
,
'布'
]
computer
=
random
.
choice
([
'石头'
,
'剪刀'
,
'布'
])
#所有赢了的情况
win
=
[[
'石头'
,
'剪刀'
],[
'布'
,
'石头'
],[
'剪刀'
,
'布'
]]
class
Text
():
def
func_play
(
self
):
ind
=
input
(
'请输入【0】石头【1】剪刀【2】布'
)
if
ind
.
isalpha
():
try
:
raise
ValueError
(
'请输入数字'
)
except
ValueError
as
v
:
print
(
v
)
elif
ind
.
isdigit
():
ind
=
int
(
ind
)
if
0
<=
ind
<=
2
:
play
=
all
[
ind
]
print
(
'你输入的是
%
s,电脑输入的是
%
s'
%
(
play
,
computer
))
if
play
==
computer
:
self
.
a
=
'平局'
elif
[
play
,
computer
]
in
win
:
self
.
a
=
'你赢了'
else
:
self
.
a
=
'你输了'
else
:
print
(
'请输入0到2之间的数'
)
print
(
self
.
a
)
def
write_file
(
self
):
with
open
(
'wuhan.txt'
,
'a'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
self
.
a
+
'n'
)
while
True
:
t
=
Text
()
t
.
func_play
()
t
.
write_file
()
\ No newline at end of file
diy1.py
View file @
6b631fcf
...
...
@@ -4,3 +4,13 @@ import random
list2
=
[
"剪刀"
,
"石头"
,
"布"
]
ji
=
random
.
choice
(
list2
)
print
(
"计算机出拳:"
+
ji
)
if
player
==
ji
:
print
(
"平局"
)
elif
player
==
"石头"
and
ji
==
"剪刀"
:
print
(
"恭喜,你赢了"
)
elif
player
==
"剪刀"
and
ji
==
"布"
:
print
(
"恭喜,你赢了"
)
elif
player
==
"布"
and
ji
==
"石头"
:
print
(
"恭喜你,你赢了"
)
else
:
print
(
"很遗憾,你输了"
)
\ No newline at end of file
jk.py
deleted
100644 → 0
View file @
9397f8e6
if
player
==
computer
:
print
(
"平局"
)
elif
player
==
"石头"
and
computer
==
"剪刀"
:
print
(
"恭喜,你赢了"
)
elif
player
==
"剪刀"
and
computer
==
"布"
:
print
(
"恭喜,你赢了)
elif player=="
布
"and computer=="
石头
":
print("
恭喜你,你赢了
")
else:
print("
很遗憾,你输了
")
\ No newline at end of file
wuhan.txt
0 → 100644
View file @
6b631fcf
平局n你输了n你输了n你赢了n你赢了n
\ 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