Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson8-1
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
a6ec2bb1
authored
Sep 27, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
98f24605
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
13 deletions
diy1.py
store.py
diy1.py
View file @
a6ec2bb1
# 这是悟空为花果山小猴做臂力测试的程序代码
name
=
input
(
'你叫啥名啊?'
)
power
=
int
(
input
(
'你臂力多少啊?'
))
list_hero
=
[
'猴三'
,
10
,
'猴一'
,
21
,
'猴五'
,
22
,
'猴队长'
,
29
,
'猴七'
,
30
]
for
i
in
range
(
len
(
list_hero
)):
if
i
%
2
==
1
and
list_hero
[
i
]
>=
power
:
list_hero
.
insert
(
i
-
1
,
name
)
list_hero
.
insert
(
i
,
power
)
break
print
(
list_hero
)
# 请注释掉上面的代码,并在下一行创建一个名为dict_hero的字典
dict_hero
=
print
(
dict_hero
)
# # 请注释掉上面的代码,并在下一行创建一个名为dict_hero的字典
# dict_hero={"猴一":50,"猴二":46,"猴三":33,"猴五":24,"猴队长":66}
# print(dict_hero)
# #通过键修改值
# dict_hero["猴队长"] = 100
# dict_hero["猴三"] = 1
# print(dict_hero)
# #添加键值对
# dict_hero['汤姆'] = 50
# dict_hero['杰瑞'] = 20
# if "汤姆" in dict_hero:
# print("汤姆在字典中")
# else:
# print("汤姆不在字典中")
# print(dict_hero)
\ No newline at end of file
store.py
0 → 100644
View file @
a6ec2bb1
store_dict
=
{
"乐事薯片"
:
5
,
"奥利奥"
:
8
,
"农夫山泉"
:
2
,
"旺仔牛奶"
:
5
,
"朱古力"
:
7
}
while
True
:
buy
=
input
(
"请问你要买啥?"
)
if
buy
in
store_dict
:
print
(
"好的,您选择的"
,
buy
,
"需要支付"
,
store_dict
[
buy
],
"元,扫码还是刷卡?"
)
else
:
print
(
"对不起,商品无货!"
)
a
=
input
(
"请选择退出还是继续购买:1=退出,2=继续购买,3=添加商品"
)
if
a
==
'1'
:
break
exit
()
elif
a
==
'2'
:
continue
elif
a
==
'3'
:
new
=
input
(
"请输入新商品名称:"
)
new_price
=
int
(
input
(
"输入价格:"
))
store_dict
[
new
]
=
new_price
\ 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