Introduction: Python Programming: Recursion
Short program that demonstrates recursion in Python.
File is attached: recursion.py
Attachments
Step 1: Code
# Example of recursion print "Example of recursion counting upwards. " # Define the function def countto100(alpha): if alpha == 100: print "Counted up to 100." elif alpha > 100: print "Number entered is greater than 100. Please enter a number less than 100. " else: print "You are at number:", alpha print "Adding one to previous number now." # Recursion below; the function calling itself countto100(alpha+1) numberentered = input("Enter a number less than 100: ") # Call the function print ("Call count to 100 function now.") countto100(numberentered)
3 Comments
8 years ago on Introduction
Before people read your recursion program, they should check out this instructable first:
https://www.instructables.com/id/Python-Programming...
Reply 2 years ago
You are implementing a recursion in real life. XD
Reply 8 years ago on Introduction
Ha! Very funny. :-)