Commit 8c243b50 by BellCodeEditor

save project

parent 6591b381
Showing with 22 additions and 5 deletions
alist=[68,75,72,81,70,78,82] alist=[68,75,72,81,70,78,82]
for i in range(0,6): for i in range(0,len(alist)-1):
for j in range(0,6): for j in range(0,len(alist)-1):
if alist[j]>alist[j+1]: if alist[j]>=alist[j+1]:
alist[j],alist[j+1] = alist[j+1],alist[j] alist[j],alist[j+1] = alist[j+1],alist[j]
print(alist) print(alist)
\ No newline at end of file
#定义一个函数sum_numbers() #定义一个函数sum_numbers()
#要求这个函数能接收一个名为num的整型参数 #要求这个函数能接收一个名为num的整型参数
#要求这个函数能计算1+2+3+……+num的结果 #要求这个函数能计算1+2+3+……+num的结果
def sum_numbers(apple):
if apple == 1:
return 1
num=apple+sum_numbers(apple-1)
return num
print(sum_numbers(998))
\ No newline at end of file
def rabbit(n):
if n>0:
if n<=2:
return 1
elif n>2:
new_rabbit=rabbit(n-1)+rabbit(n-2)
return new_rabbit
else:
return 0
print(rabbit(10))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment