ValueError: invalid literal for int() with base 10
Question: I am a beginner in python. I came across this question in codewars.

_Jaden is known for some of his philosophy that he delivers via Twitter. When
writing on Twitter, he is known for almost always capitalizing every word.
Your task is to convert strings to how they would be written by Jaden Smith.
The strings are actual quotes from Jaden Smith, but they are not capitalized
in the same way he originally typed them._

Example :

_Not Jaden-Cased: "How can mirrors be real if our eyes aren't real"_

_Jaden-Cased: "How Can Mirrors Be Real If Our Eyes Aren't Real"_

This is my attempt (I am supposed to code using a function)

    
    
    def toJadenCase(string):
        l = len(string)
        for i in range(0,l):
            if string[i] == ' ':
                y = string[i]
                string[i+1] = chr(int(y)-32)
        return srting
    s = raw_input()
    print toJadenCase(s)
    

When run, the following errors showed up

    
    
    How can mirrors be real if our eyes aren't real  (this is the input string)
    Traceback (most recent call last):
      File "jaden_smith.py", line 9, in <module>
        print toJadenCase(s)
      File "jaden_smith.py", line 6, in toJadenCase
        string[i+1] = chr(int(y)-32)
    ValueError: invalid literal for int() with base 10: ''
    

I couldn't understand these errors even after google-ing it. Any help would be
appreciated. I would also be great if other errors in my code are highlighted
and a better code is suggested.

Thanks in advance :D


Answer: **As Goodies points out, string should not be used as a variable name**

Following the [Zen of Python](http://c2.com/cgi/wiki?PythonPhilosophy), this
is technically a function that does exactly what you're trying to achieve:

    
    
    def toJadenCase(quote):
        return quote.title()
    

Edit:

Revised version to deal with apostrophes:

    
    
    import string
    
    def toJadenCase(quote):
        return string.capwords(quote)
    

