A list of FreeCodeCamp's JavaScript bonfire excerises completed using Python 3.
Last active
August 12, 2016 14:09
-
-
Save awalx/95bdc875ebd71005b90209f406471635 to your computer and use it in GitHub Desktop.
FreeCodeCamp Bonfire exercises using Python 3
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
#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)) |
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
#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