Created
March 5, 2019 01:34
-
-
Save andresdhn/6dff4437394c79f19b175f9fef746f54 to your computer and use it in GitHub Desktop.
This simple gist will create a Python emulator for the range() function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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