-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Brute-force argorithms", exercise 4 #19
Labels
Comments
|
def my_range(stop_number):
result= list()
i = 0
while 0 <= i < stop_number:
i += 1
result.append((i-1))
return result
# Test case
def test_range(stop_number, expected):
if my_range(stop_number)== expected:
return True
else:
return False
# Three test runs
print(test_range(4, [0, 1, 2, 3]))
print(test_range(4, [0, 1, 2, 3, 4]))
print(test_range(4, list(range(4)))) |
|
def test_my_range (stop_number, expected):
result = my_range(stop_number)
if result == expected:
return True
else:
return False
def my_range(stop_number):
output_list = []
iterating_number = 0
while iterating_number < stop_number:
output_list.append (iterating_number)
iterating_number += 1
return output_list
#Test case
print(test_my_range(4, [0, 1, 2, 3]))
print(test_my_range(8, [0, 1, 2, 3, 4, 5, 6, 7]))
#Console output
True
True |
# test case for the algorithm
def test_my_range(stop_number, expected):
result = my_range(stop_number)
if expected == result:
return True
else:
return False
def my_range(stop_number):
output_list = list()
n = 0
while n < stop_number:
output_list.append(n)
n = n + 1
return output_list
print(test_my_range((4),([0,1,2,3]))) |
|
|
def test_my_range(n, expected): def my_range(n):
print(test_my_range(6, [0, 1, 2, 3, 4, 5])) |
def my_range(stop_number):
count=0
output_list = []
while count<stop_number:
output_list.append(count)
count+=1
return output_list
def test_my_range(stop_number,expected):
if my_range(stop_number) == expected:
return True
else:
return False
print(test_my_range(5,[0,1,2,3,4]))
print(test_my_range(3,[0,1,2])) |
|
def test_my_range(stop_number, expected):
result = my_range(stop_number)
if expected == result:
return True
else:
return False
def my_range(stop_number):
range_object = []
start_number = 0
while start_number < stop_number:
range_object.append(start_number)
start_number += 1
return range_object
print(test_my_range(5, [0, 1, 2, 3, 4]))
print(test_my_range(0, [])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write in Python the function
def my_range(stop_number)
, which behave like the built-in functionrange()
introduced in Section "Insertion sort" and returns a proper list, and accompany the function with the related test case. It is not possible to use the built-in functionrange()
in the implementation.The text was updated successfully, but these errors were encountered: