Python 实现 range()
本帖最后由 zltzlt 于 2020-3-24 17:42 编辑Python 实现 range()
题目要求
1. 实现 range() 内置函数
2. 不得使用内置模块
格式
def myRange(*args):
# write your code here
例子
>>> list(myRange(5))
>>> list(myRange('5'))
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
list(myRange('5'))
TypeError: 'str' object cannot be interpreted as an integer
>>> list(myRange())
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
list(myRange())
TypeError: range expected 1 argument, got 0
>>> list(myRange(1, 2, 3, 4))
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
list(myRange(1, 2, 3, 4))
TypeError: range expected at most 3 arguments, got 4
>>> list(myRange(5, 10))
>>> list(myRange(10, 100, 6))
>>> list(myRange(100, 10, -6))
>>> list(myRange(15, 30, -5))
[]
>>> list(myRange(30, 15, 5))
[]
NOW, IT'S YOUR SHOWTIME ! {:10_256:}
页:
[1]