Last active
December 20, 2015 03:49
-
-
Save robrocker7/6066482 to your computer and use it in GitHub Desktop.
Very Basic Recursive Function Example in Python
This file contains hidden or 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
# Example recursive | |
import random | |
def recursive_check(loop=1): | |
""" This is a very basic recursive example. | |
Each recursive loop grabs a random number between 1 and 10 and checks to see if its 7. | |
The loop will record how many attemps it takes and return the number when the random integer is 7. | |
""" | |
random_int = random.randrange(10) | |
if random_int == 7: | |
print 'Number was 7! Took {0} steps'.format(loop) | |
return | |
print 'Number was {0}'.format(random_int) | |
recursive_check(loop+1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment