Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:37:06+00:00 2026-06-09T03:37:06+00:00

I have this python program that adds strings to integers: a = raw_input("Enter a:

  • 0

I have this python program that adds strings to integers:

a = raw_input("Enter a: ")
b = raw_input("Enter b: ")
print "a + b as strings: " + a + b
a = int(a)
b = int(b)
c = a + b
str(c)
print "a + b as integers: " + c

I get this error:

TypeError: cannot concatenate 'str' and 'int' objects

How can I add strings to integers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:37:08+00:00Added an answer on June 9, 2026 at 3:37 am

    There are two ways to fix the problem which is caused by the last print statement.

    You can assign the result of the str(c) call to c as correctly shown by @jamylak and then concatenate all of the strings, or you can replace the last print simply with this:

    print "a + b as integers: ", c  # note the comma here
    

    in which case

    str(c)
    

    isn’t necessary and can be deleted.

    Output of sample run:

    Enter a: 3
    Enter b: 7
    a + b as strings:  37
    a + b as integers:  10
    

    with:

    a = raw_input("Enter a: ")
    b = raw_input("Enter b: ")
    print "a + b as strings: " + a + b  # + everywhere is ok since all are strings
    a = int(a)
    b = int(b)
    c = a + b
    print "a + b as integers: ", c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python program (with Django - does this matter?) that I want
I have this code in Python inputted = input(Enter in something: ) print(Input is
I'm having troubles getting this to work. Basically I have a python program that
I have a python program that does something like this: Read a row from
I have a python program that uses a custom-built DLL. This DLL crashes due
I have a program that is run from the command line like this python
I have this program in Python which should save text files to a folder
I have this code: def display(self): print self.doc.toprettyxml(indent= ) strigName ='/Users/my_user/Desktop/python/' + str(datetime.datetime.now()) +
I've been playing with Python and I have this list that I need worked
I have this program that check a website, and I want to know how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.