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
e1b7f4c0
authored
Jul 11, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
85e4b26e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
11 deletions
diy1.py
diy1.py
View file @
e1b7f4c0
n
=
int
(
input
(
'输入一个正整数N:'
))
'''
ren
=
list
(
range
(
1
,
n
+
1
))
import random
count
=
0
player=input("请出拳:") # 输入,括号里填提示语
while
len
(
ren
)
>
1
:
print("玩家出拳:"+player)
new_ren
=
ren
[:]
# 把原列表拷贝到新列表中,用于限制循环的次数
list=["石头","剪刀","布"]
# 开始报数
computer=random.choice(list)
for
i
in
range
(
0
,
len
(
new_ren
)):
# 从第一个人开始报数
print("计算机出拳:"+computer)
count
=
count
+
1
# 每报一次,计数器+1
if player in list:
if
count
%
3
==
0
:
if player==computer:
ren
.
remove
(
new_ren
[
i
])
print("平局")
print
(
'{}'
.
format
(
ren
[
0
]))
elif (player=="石头" and computer=="剪刀")
\
or (player=="剪刀" and computer=="布")
\
or (player=="布" and computer=="石头"):
print("玩家赢")
else:
print("玩家输")
else:
print("输入错误")
'''
'''
random模块是随机数模块,用的时候需要先导入:
import random
random.choice() 随机选取
条件判断:
单分支:
if 条件:
满足条件要执行的内容
双分支:
if 条件1:
满足条件要执行的内容
else:
满足条件要执行的内容
多分支:
if 条件1:
执行内容
elif 条件2:
执行内容
elif 条件3:
执行内容
...
else:
满足条件要执行的内容
关键字 in
a in b 表示a在b里面
关键字 not in
a not in b 表示a不在b里面
'''
# tup=("apple")
# tup1=("apple",)
# print(type(tup))
# print(type(tup1))
#format格式化字符串
def
introduce
(
name
,
age
):
print
(
"我叫{},我今年{}岁"
.
format
(
name
,
age
))
introduce
(
"许正家"
,
13
)
# {}作为占位符,通过传入的参数替换占位符,就得到格式化后的字符串
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