TypeError: Can't convert 'int' object to str implicitly *Python*
Question: For an assignment i am trying to get the results of a form "age" and to add
one to that number using python. The form will have users enter their age and
result should be their age next year.

Here is what i have thus far:

    
    
    import cgi
    form = cgi.FieldStorage()
    
    name = str(form.getvalue("name"))
    age = int(form.getvalue("age"))
    
    print ("""Content-type: text/html
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html><head>
    <title>Lab 9</title>
    </head><body>
    """)
    
    print ("<p>Hello," +name+ ".</p>")
    print ("Next year you will be" + str(age+1) + "years old")
    print ("</body></html>") 
    

The error i get is

    
    
    Traceback (most recent call last):
        File "/Users/JLau/Documents/CMPT 165/Lab 9/result.py", line 19, in <module>
            print ("Next year you will be" + str(age + 1) + "years old")
        TypeError: Can't convert 'int' object to str implicitly"
    

I somehow need to convert the value of age to and "int" to which a number can
be added, not sure how to do this.


Answer: That can't be the code you're running.

Check the following test.

    
    
    >>> age = 20
    >>> print ("Next year you will be" + str(age+1) + "years old")
    Next year you will be21years old
    >>> age = '20'
    >>> print ("Next year you will be" + str(age+1) + "years old")
    Traceback (most recent call last):
      File "<pyshell#4>", line 1, in <module>
        print ("Next year you will be" + str(age+1) + "years old")
    TypeError: Can't convert 'int' object to str implicitly
    

You'll get this error if `age` is a string.

Please add a line with

    
    
    print(type(age))
    

and look at the result.

