Sign Up

Have an account? Sign In Now

Sign In

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

Sorry, you do not have a permission to ask a question, You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

ErrorCorner

ErrorCorner Logo ErrorCorner Logo

ErrorCorner Navigation

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

Mobile menu

Close
Ask a Question
  • Home
  • Contact Us
  • About Us
Home/ Questions/Q 425
Next
Answered
Kenil Vasani
Kenil Vasani

Kenil Vasani

  • 646 Questions
  • 567 Answers
  • 77 Best Answers
  • 26 Points
View Profile
  • 8
Kenil Vasani
Asked: December 11, 20202020-12-11T20:36:22+00:00 2020-12-11T20:36:22+00:00In: Python

How to resolve TypeError: can only concatenate str (not “int”) to str

  • 8
This question already has answers here:

How can I concatenate str and int objects?

(4 answers)

How can I read inputs as numbers?

(10 answers)

String concatenate TypeError: can only concatenate str (not “int”) to str”

(3 answers)

Closed 6 months ago.

  • I decided to make some kind of secret code for testing purposes with Unicode.
  • I’ve done that by adding numbers to Unicode so it would be kind of secret.
  • I’ve been getting this error, but I don’t know how to solve it.
    • Is there any solution?

Original Code

message = input("Enter a message you want to be revealed: ")
secret_string = ""
for char in message:
    secret_string += str(chr(char + 7429146))
print("Revealed", secret_string)
q = input("")

Original Error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-182-49ece294a581> in <module>
      2 secret_string = ""
      3 for char in message:
----> 4     secret_string += str(chr(char + 7429146))
      5 print("Revealed", secret_string)
      6 q = input("")

TypeError: can only concatenate str (not "int") to str

Updated code

while True:
    try:
        message = int(input("Enter a message you want to be decrypt: "))
        break
    except ValueError:
        print("Error, it must be an integer")
secret_string = ""
for char in message:
    secret_string += chr(ord(char - str(742146)))
print("Decrypted", secret_string)
q = input("")
pythonunicode
  • 1 1 Answer
  • 11 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    1. Rohit Patel

      Rohit Patel

      • 0 Questions
      • 98 Answers
      • 0 Best Answers
      • 0 Points
      View Profile
      Best Answer
      Rohit Patel
      2020-12-11T20:35:26+00:00Added an answer on December 11, 2020 at 8:35 pm

      Python working a bit differently to JavaScript for example, the value you are concatenating needs to be same type, both int or str…

      So for example the code below throw an error:

      print( "Alireza" + 1980)
      

      like this:

      Traceback (most recent call last):
        File "<pyshell#12>", line 1, in <module>
          print( "Alireza" + 1980)
      TypeError: can only concatenate str (not "int") to str
      

      To solve the issue, just add str to your number or value like:

      print( "Alireza" + str(1980))
      

      And the result as:

      Alireza1980
      
      • 3
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Sidebar

    Ask A Question
    • Popular
    • Kenil Vasani

      SyntaxError: invalid syntax to repo init in the AOSP code

      • 5 Answers
    • Kenil Vasani

      xlrd.biffh.XLRDError: Excel xlsx file; not supported

      • 3 Answers
    • Kenil Vasani

      Homebrew fails on MacOS Big Sur

      • 3 Answers
    • Kenil Vasani

      runtimeError: package fails to pass a sanity check for numpy ...

      • 3 Answers
    • Kenil Vasani

      ERROR: torch has an invalid wheel, .dist-info directory not found

      • 2 Answers

    Explore

    • Most Answered
    • Most Visited
    • Most Voted
    • Random

    © 2020-2021 ErrorCorner. All Rights Reserved
    by ErrorCorner.com