Lecture "Brute-force argorithms", exercise 4
essepuntato opened this issue · 11 comments
essepuntato commented
Write in Python the function def my_range(stop_number)
, which behave like the built-in function range()
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 function range()
in the implementation.
n1kg0r commented
def test_my_range(input_range_list, expected):
return input_range_list == expected
def my_range(stop_number):
output_list = []
current_iterating_number = 0
while current_iterating_number < stop_number:
output_list.append(current_iterating_number)
current_iterating_number += 1
return output_list
# Expect True
print(test_my_range(my_range(4), [0, 1, 2, 3]))
print(test_my_range(my_range(4), list(range(4))))
# Console output: True
delete4ever commented
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))))
alka2696 commented
#Test case for the function
def test_my_range(stop_number, expected):
result = my_range(stop_number)
if expected == result:
return True
else:
return False
# Code of the function
def my_range(stop_number):
result = list()
while stop_number > 0:
stop_number = stop_number - 1
result.insert(0, stop_number)
return result
print(test_my_range(4, [0, 1, 2, 3,]))
print(test_my_range(10, [0, 1, 2, 3,]))
lucia1299 commented
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
giorgiacrosilla commented
# 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])))
EricaAndreose commented
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_list=[]
number=0
while number < stop_number:
range_list.append(number)
number += 1
return range_list
# Test runs that return True
print(test_my_range((4), [0, 1, 2, 3]))
print(test_my_range((10), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
print(test_my_range((7), [0, 1, 2, 3, 4, 5, 6]))
matteo-guenci commented
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):
ranged_list = []
x = 0
while x < stop_number:
ranged_list.append(x)
x += 1
return ranged_list
print(test_my_range((7), ([0, 1, 2, 3, 4, 5, 6])))
SpedicatiDaniele commented
def test_my_range(n, expected):
result = my_range(n)
if result == expected:
return True
else:
return False
def my_range(n):
output_list = list()
x = 0
while x < n:
output_list.append(x)
x += 1
return output_list
print(test_my_range(6, [0, 1, 2, 3, 4, 5]))
print(test_my_range(0, []))
ranacoskun commented
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]))
corrado877 commented
#Test case algorithm
def test_case_my_range(stop_number, expected):
result=my_range(stop_number)
if result==expected:
return True
else:
return False
# Code of algorithm
def my_range (stop_number):
output_list=[]
x=0
while x < stop_number:
output_list.append (x)
x=x+1
return output_list
# three test runs
print (test_case_my_range (3, [0, 1, 2]))
print (test_case_my_range (5, [0, 1, 2, 3, 4]))
print (test_case_my_range(0, []))
ChiaraParravicini commented
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, []))