Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson10-5
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
da7ddc50
authored
Oct 16, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
eb2dbbaa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
17 deletions
diy.py
diy2.py
diy.py
View file @
da7ddc50
# 报菜名
'''
# 悟空和诺依到了一家特色餐馆,这家餐馆最大的特色就是有个自动报菜名机器人
有一只猴子,第一天摘了很多桃子,可是它忍不住在第一天的时候,吃了一半的桃子后,
# 通常它会自动说出今天的前菜有哪些汤有哪些主菜有哪些等等~
又吃了一个,接下来,第二天吃了前一天剩余桃子数量的一半多一个,第十天只剩1个,问
# 可是今儿它有些bug产生的结果很奇怪,你可以检查出来么?
第一天一共摘了多少个桃子?
today_menu
=
{
'前菜'
:{
'熏鲢鱼'
:
20
,
'生蚝'
:
20
,
'面包'
:
10
},
'''
'汤'
:{
'玉米浓汤'
:
15
,
'蔬菜汤'
:
15
,
'海鲜汤'
:
15
},
# def peach(n): #n表示天数
'主菜'
:{
'鱼'
:
40
,
'虾'
:
30
,
'蟹'
:
20
,
'贝壳类'
:
20
},
# if n == 10: #如果天数为10的话
'间菜'
:{
'牛扒'
:
25
,
'煨菜'
:
25
,
'肉排'
:
30
},
# return 1 #返回最终桃子数量剩余1
"烧烤和沙拉"
:{
'需要'
:
15
,
'不需要'
:
0
},
# num = (peach(n + 1) + 1) * 2
'甜品'
:{
'可丽露'
:
20
,
'优格吐司'
:
15
,
'蓝莓松饼'
:
20
}
# return num
}
for
k
,
v
in
today_menu
.
items
():
# peach_num = peach(9)
print
(
'今日'
+
k
+
'有:'
)
# print('第九天还剩',peach_num,'个桃子。')
for
i
in
v
:
# print('第一天猴子一共摘了',peach(1),'个桃子。')
print
(
i
,
end
=
' '
)
#依次告诉客人今天的各类菜有哪些选择
print
()
\ No newline at end of file
'''
计算1,2,3,4...n的累加和。
'''
# #传统程序(枚举法)
# sum = 0 #声明一个变量sum,来表示累加和
# n = 100
# for i in range(1,n+1): #利用for循环遍历i的值。从1一直到100
# sum = sum + i
# print(sum)
# #递归方法
# def sum_numbers(num):
# #递归出口
# if num == 1: #如果num为1,表示累加结束
# return 1
# #数字的累加
# temp = sum_numbers(num-1) #每一次调用,计算加到当前num-1数值的和
# return num + temp #将累加结果返回
# result = sum_numbers(100) #调用方法,传入参数100
# print(result) #输出结果
'''
斐波那契数列
'''
def
func
(
n
):
if
n
<=
2
:
return
1
elif
n
>
2
:
value
=
func
(
n
-
1
)
+
func
(
n
-
2
)
return
value
result
=
func
(
8
)
print
(
result
)
\ No newline at end of file
diy2.py
0 → 100644
View file @
da7ddc50
import
random
as
r
#重命名random模块
a
=
r
.
randint
(
1
,
10
)
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