Created
June 9, 2015 17:35
-
-
Save WikiWookie/821cb46f5f58d7519ccb to your computer and use it in GitHub Desktop.
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
""" | |
Write a function that receives a string and returns a camel case version of it. | |
Example: | |
camel_case('hello world') # Hello World | |
""" | |
def camel_case(a_string): | |
# Cycle through string | |
# Remember a string is a sequence of characters | |
for char in a_string: | |
# Check to see if the char is the first char | |
# If so, change it to upper case | |
# Also, the upper variable tells you if you have already | |
# changed a letter to upper for the duration of the word | |
if char == a_string[0]: | |
char = char.upper() | |
upper = True | |
if upper == False: | |
char = char.upper() | |
upper = True | |
#checks to see if char is a space | |
# If so, reset upper boolean | |
if char == ' ': | |
upper = False | |
print a_string | |
return a_string | |
camel_case('hello world') | |
camel_case('yo this is a string') | |
camel_case('uh one final test') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment