Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- 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')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement