Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. """
  2. Write a function that receives a string and returns a camel case version of it.
  3. Example:
  4. camel_case('hello world') # Hello World
  5. """
  6.  
  7.  
  8. def camel_case(a_string):
  9. # Cycle through string
  10. # Remember a string is a sequence of characters
  11. for char in a_string:
  12.  
  13. # Check to see if the char is the first char
  14. # If so, change it to upper case
  15. # Also, the upper variable tells you if you have already
  16. # changed a letter to upper for the duration of the word
  17. if char == a_string[0]:
  18. char = char.upper()
  19. upper = True
  20. if upper == False:
  21. char = char.upper()
  22. upper = True
  23.  
  24. #checks to see if char is a space
  25. # If so, reset upper boolean
  26. if char == ' ':
  27. upper = False
  28.  
  29. print a_string
  30. return a_string
  31.  
  32. camel_case('hello world')
  33. camel_case('yo this is a string')
  34. camel_case('uh one final test')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement