Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson8-4
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
dae678b9
authored
Jun 29, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
9ed85b40
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
9 deletions
424.py
426.py
diy.py
424.py
0 → 100644
View file @
dae678b9
n
=
int
(
input
())
# 以5个人为例
ren
=
list
(
range
(
1
,
n
+
1
))
#将所有人都放入一个人列表中 [1,2,3,4,5]
c
=
0
#用来计算报数
while
len
(
ren
)
>
1
:
#当列表中至少有2人的时候,进行循环
new_ren
=
ren
[:]
#把原来的列表复制到新列表中,用来限制for循环的次数
#print(new_ren)
for
i
in
range
(
0
,
len
(
new_ren
)):
#从第一个人开始报数
c
+=
1
if
c
%
3
==
0
:
# 如果报到3
ren
.
remove
(
new_ren
[
i
])
#把报到3的人从列表中删除,进行下一轮循环
print
(
new_ren
[
1
])
426.py
0 → 100644
View file @
dae678b9
for
i
in
range
(
2
,
0
,
-
1
):
print
(
i
)
# range( , , )
# 开始 结尾 步长
# 默认0 不包含 默认1
%
操作符
字符串输出
%
d
,
%
d
是字符串占位符,把一个数据项转换为字符串。
diy.py
View file @
dae678b9
# 神奇百货中的物品已经帮你创建好啦,接下来要看你的了~
n
=
input
()
dict
=
{
'可口可乐'
:
3
,
'旺仔牛奶'
:
4
,
'农夫山泉'
:
1
,
'辣条'
:
3
,
'巴西烤肉'
:
2
,
'果冻'
:
4
,
'乐事'
:
5
,
'奥利奥'
:
10
,
'巧克力'
:
6
}
list
=
n
.
split
(
' '
)
# 以空格分隔,并把分隔好的数字以字符串的形式存放到列表里
j
=
input
(
"你要买什么?"
)
print
(
list
)
if
j
in
dict
:
new_list
=
[]
# 用来把list里的字符串转换为整型存放到new_list中
prink
(
'巧克力'
(
dict
[
j
]))
for
i
in
list
:
new_list
.
append
(
int
(
i
))
else
:
print
(
new_list
)
prink
()
ping
=
sum
(
new_list
)
/
len
(
new_list
)
# 平均值
\ No newline at end of file
da
=
max
(
new_list
)
# 最大值
xiao
=
min
(
new_list
)
# 最小值
print
(
da
,
xiao
,
'
%.2
f'
%
ping
,
sep
=
','
)
\ 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