Skip to content

Instantly share code, notes, and snippets.

@andresdhn
Created March 5, 2019 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andresdhn/6dff4437394c79f19b175f9fef746f54 to your computer and use it in GitHub Desktop.
Save andresdhn/6dff4437394c79f19b175f9fef746f54 to your computer and use it in GitHub Desktop.
This simple gist will create a Python emulator for the range() function
#
# Creating a range() emulator for my big Bro
#
#
# Mens Let's define a function where the magic happens
# @param: num => integer
# @returns: range
#
def magic(num):
#
# We declare an Array o arreglo o lista
# to store the range numbers
#
list = []
index = 0
limit = num + 1
#
# Mientras index que empieza en 0 sea menor que el limite date otra vuelta
# El limite sera el numero provided mas uno
# Se le suma 1 al limite porque While corre mientras sea menor....
# otra opcion seria usar <= y no sumar uno al limite...
# pero tu quieres la version trucutu
#
sumAccumulate = int(index) + 1
while int(index) < int(limit):
list.append(index)
print str(index) + ' + ' + str(sumAccumulate) + ' = ' + str(int(index) + int(sumAccumulate))
sumAccumulate = int(sumAccumulate) + int(index)
index = int(index) + 1
return list
#
# We print the function
# Replace number with desired shit!
#
print magic(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment