Skip to content

Instantly share code, notes, and snippets.

@awalx
Last active August 12, 2016 14:09
Show Gist options
  • Save awalx/95bdc875ebd71005b90209f406471635 to your computer and use it in GitHub Desktop.
Save awalx/95bdc875ebd71005b90209f406471635 to your computer and use it in GitHub Desktop.
FreeCodeCamp Bonfire exercises using Python 3
#Factorialize a number
def factorialize(num):
if num == 0:
#0! = 1
return 1
else:
#use a recursive call to factorialize, n! = n*(n-1)!
return int(num) * factorialize(int(num) - 1)
print('Enter an integer to factorialize:')
myInt = input()
print(factorialize(myInt))

FreeCodeCamp Bonfire exercises using Python 3

A list of FreeCodeCamp's JavaScript bonfire excerises completed using Python 3.

#Reverse a string
def reverseStr(s):
s = list(s) #convert string to list
s.reverse() #reverse the list
newString = '' #start new blank string
for i in s: #loop through each character in the list
newString += i #add each character to form the new string
print(newString) #print new string
print('Enter a string:')
myString = input() #take input from user
reverseStr(myString) #call reverseStr function on user input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment