Giter VIP home page Giter VIP logo

Comments (17)

edoardodalborgo avatar edoardodalborgo commented on July 24, 2024
def test_my_range(stop_number):
    counts = 0
    for a in my_range(stop_number):
        counts += 1
    if counts == stop_number:
        return True
    else: return False

def my_range(stop_number):
    my_range_list = []
    i = 0
    while i < stop_number:
        my_range_list.append(i)
        i += 1
    return my_range_list

x = int(input("Enter the range that you would obtain: "))
print(test_my_range(x))

from 2020-2021.

diegochillo avatar diegochillo commented on July 24, 2024
def my_range(stop_number):
   my_range=list()
   n=0
   while (n<stop_number):
	my_range.insert(n,n)
	n=n+1
	
   return my_range


def test_my_range(stop_number, expected):
   result=my_range(stop_number)
   return result==expected

print(test_my_range(5, [0,1,2,3,4]))

from 2020-2021.

gabrielefiorenza avatar gabrielefiorenza commented on July 24, 2024
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):
    result = []
    number = 0
    result.append(number)
    while number != (stop_number -1):
        number += 1
        result.append(number)
    return result


print (test_my_range(4,[0,1,2,3]))
print (test_my_range(3,[0,1]))

from 2020-2021.

dbrembilla avatar dbrembilla commented on July 24, 2024
def test_my_range(stop_number, expected):
    result=my_range(stop_number)
    return result ==expected

def my_range(stop_number):
    x = 0
    my_range_list = list()
    while x < stop_number:
        my_range_list.append(x)
        x += 1
    return my_range_list

print(test_my_range(4, [0 , 1, 2, 3]))

from 2020-2021.

ChiaraCati avatar ChiaraCati commented on July 24, 2024
# Test
def test_my_range(stop_number, expected):
    result = my_range(stop_number)
    if result == expected:
        return True
    else:
        return False

# Function    
def my_range(stop_number):
    my_list = []
    c=0
    while c < stop_number:
        my_list.append(c)
        c+=1
    return my_list
    
#print(my_range(6))

print(test_my_range(6, ([0, 1, 2, 3, 4, 5]))) # Output : True
print(test_my_range(4, ([1, 2, 3, 4])))  # Output : False
print(test_my_range(0, ([0]))) # Output : False
print(test_my_range(0, ([]))) # Output : True

me and Giorgia Sampò did it together

👭

from 2020-2021.

fcagnola avatar fcagnola commented on July 24, 2024
# Write in Python the function def my_range(stop_number) which behaves 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.

def test(stop_number, expected):
    result = my_range(stop_number)
    if result == expected:
        return True
    else:
        return False

def my_range(stop_number):
    result_list = [] # creates the final result, as a list object
    number = 0 # sets the starting point at 0
    while number != stop_number: # loops through integers between 0 and stop_number
        result_list.append(number) # adds each loop value to the final list
        number += 1
    return result_list #returns the result

print(test(5, [0, 1, 2, 3, 4])) # returns True
print(test(19, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18])) # returns True

from 2020-2021.

AleRosae avatar AleRosae commented on July 24, 2024
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):
    n = 0
    my_list = list ()
    while n != stop_number:
        my_list.append(n)
        n=n + 1


    return my_list

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((0), []))

from 2020-2021.

AlessandraFa avatar AlessandraFa commented on July 24, 2024
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):
    a = 0
    range_list = list()
    while a < stop_number:
        range_list.append(a)
        a += 1
    return range_list


print(test_my_range((8), [0, 1, 2, 3, 4, 5, 6, 7]))
print(test_my_range((1), [0]))

from 2020-2021.

yunglong28 avatar yunglong28 commented on July 24, 2024
#This is the function that simulates range()

def my_range (stop_number):
    range = []
    n = 0
    while n < stop_number:
        range.append(n)
        n=n+1
    return range
print(my_range(8))
#This is the test function
def test_myrange (stop_number, expected):
    result = my_range(stop_number)
    if result == expected:
        return True
    else:
        return False
print(test_myrange(8, [0, 1, 2, 3, 4, 5, 6, 7]))

from 2020-2021.

SusannaPinotti avatar SusannaPinotti commented on July 24, 2024
def test_my_range(stop_number, expected):
    res = my_range(stop_number)
    if expected == res:
        return True
    else:
        return False

def my_range(stop_number):
    output_list = list()
    n = 0
    while n < stop_number:
        output_list.append (n)
        n += 1
    return output_list

print(test_my_range((6), [0,1,2,3,4,5])) #return True
print(test_my_range((0), [])) #returns True
print(test_my_range((0), [0])) #return False

from 2020-2021.

IlaRoss avatar IlaRoss commented on July 24, 2024
#test
def test_my_range(stop_number, range_list):
    result = my_range(stop_number)
    if result == range_list:
        return True
    else:
        return False

#algorithm
def my_range(stop_number):
    range_list = list()
    prov_list = list()
    prov_number = (stop_number-1)

    if stop_number == 0:
        return range_list

    elif stop_number < 0:
        return 'Error'

    else:

        while prov_number >= 0:
            prov_list.append(prov_number)
            prov_number -= 1

        for item in prov_list:
            range_list.insert(0, item)

        return range_list



#test runs
print(test_my_range(5, [0, 1, 2, 3, 4]))
print(test_my_range(0, []))
print(test_my_range(-3, 'Error'))

#algorithm execution
print(my_range(12))
print(my_range(0))
print(my_range(-15))

from 2020-2021.

LuisAmmi avatar LuisAmmi commented on July 24, 2024
# test
def test_my_range(stop_number, expected):
    result = my_range(stop_number)
    if result == expected:
        return True
    else:
        return False


# code
def my_range(stop_number):
    output_list = list()
    n = 0                  # initialize n
    while n != stop_number:
        output_list.append(n)
        n += 1
    else:
        return output_list


print(test_my_range(3, [0, 1, 2]))
print(test_my_range(2, [0, 1]))
print(test_my_range(0, []))```

from 2020-2021.

vanessabonanno avatar vanessabonanno commented on July 24, 2024
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):
    my_list = []
    x = 0
    while x < stop_number:
        my_list.append(x)
        x += 1
    return my_list


print(test_my_range(4, [0, 1, 2, 3]))# output: True
print(test_my_range(2, [1, 2]))      # output: False (starting number will be 0,
                                     # not 1 because x=0; 2 is not included in list since
                                     # there is '<' and not 'less or equal to')
print(my_range(4))                   # [0, 1, 2, 3]


from 2020-2021.

AlessandroBertozzi avatar AlessandroBertozzi commented on July 24, 2024
def test_my_range(stop_number, expected):
    result = my_range(stop_number)
    if result == expected:
        return True
    return False


def my_range(stop_number):
    counter = 0
    list_number = []
    while counter < stop_number:
        list_number.append(counter)
        counter += 1
    return list_number


print(test_my_range(3, [0, 1, 2]))
print(test_my_range(7, [0, 1, 2, 3, 4, 5, 6]))
print(test_my_range(0, []))

from 2020-2021.

SarahTew avatar SarahTew commented on July 24, 2024

def my_range(stop_number):
    if stop_number>=0:
        n=0
        range_result=list()
        while n<stop_number:
            range_result.append(n)
            n=n+1
        return(range_result)
    else:
        return("Negative Number!")
        
#print ranges    
print(my_range(5))
print(my_range(3))
print(my_range(-5))
print(my_range(0))
print(my_range(3.3))

#test my_range function
def test_my_range(stop_number, expected):
    result=my_range(stop_number)
    if result==expected:
        return True
    else:
        return False
print(test_my_range(3, [0, 1, 2]))
print(test_my_range(0, []))
print(test_my_range(-9, "Negative Number!"))

from 2020-2021.

essepuntato avatar essepuntato commented on July 24, 2024

Hi all,

A general comment: can you try to run the range function in Python with the following input, to see what actually happens? Does your function work as the original one?

range(-4)

from 2020-2021.

SofiBar avatar SofiBar commented on July 24, 2024

exercise 4:

`def test_my_range(stop_number, expected):
    if expected == my_range(stop_number):
        return True
    else:
        return False

def my_range(stop_number):
    count = 0
    output_list = []

    while count < stop_number:
        output_list.append(count)
        count += 1
    return output_list


print(test_my_range(5, [0, 1, 2, 3, 4]))
print(test_my_range(7, [0, 1, 2, 3, 4, 5, 6]))
print(test_my_range(4, [0, 1, 2, 3]))

Range issue:
if I write a negative number my function returns an empty list because -4 is less than 0 so the condition is never true.

from 2020-2021.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.