用户:
三年忘更的梁珂玮查看:1 回复:2 评论:1 创建时间:2021-05-22T15:07:26
【作品展示】

【作品介绍】
语法介绍:myRange(start,end,step)
start:必填项,开始的数字(必须是整数)
end:必填项,结束的数字(必须是整数)
step:可选项,两个参数之间隔的数(必须是整数,默认是1)
【作品源代码】
#!usr/bin/env/ python3
# -*- coding: utf-8 -*-
def myRange(start,end,step=1):
a = []
i = start
while i < end:
a.append(i)
i += step
return a
print(myRange(0,16))
print(myRange(2,17,2))
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cndef myRange(*s):
rangeList = []
if len(s) == 1:
start, end, step = 0, s[0], 1
elif len(s) == 2:
start, end, step = s[0], s[1], 1
else:
start, end, step = s[0:3]
i = 0
if step == 0:
print('Error: Step = 0')
return []
elif step > 0:
while i < end:
rangeList.append(i)
i += step
return rangeList
else:
while i > end:
rangrList.append(i)
i -= step
return rangeList
'''更新内容:
1、start不是必选项
2、参数数量可变
3、支持结束项负数'''点赞0
评论