Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def my_range(*args):
- number_of_args = len(args)
- if number_of_args == 1:
- start, stop, step = 0.0, args[0], 1.0
- elif number_of_args == 2:
- start, stop, step = args[0], args[1], 1.0
- elif number_of_args == 3:
- start, stop, step = args[0], args[1], args[2]
- else:
- raise ValueError("Function needs 1 to 3 arguments.")
- if step == 0:
- raise ValueError("Step argument cannot be 0")
- result = []
- while step > 0 and start < stop:
- result.append(start)
- start += step
- while step < 0 and start < stop:
- result.append(stop)
- stop += step
- return result
- def main():
- try:
- print(my_range(1.1, 2.2, 0.5))
- print(my_range(1.1, 2.1, 0.5))
- print(my_range(1.1, 2.2))
- print(my_range(2.2))
- print(my_range(1.1, 2.2, -0.5))
- print(my_range())
- except ValueError as e:
- print("Error: ", e)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement