Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import perf_counter
- def my_range(*args):
- number_of_args = len(args)
- start_timer = perf_counter()
- 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
- end_timer = perf_counter()
- print("Czas działania programu: ", end_timer - start_timer)
- return result
- def main():
- try:
- my_range(1.0, 1000, 0.5)
- my_range(1.0, 10000, 0.5)
- my_range(1.0, 100000, 0.5)
- my_range(1.0, 1000000, 0.5)
- except ValueError as e:
- print("Error: ", e)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement