+ 1

(solved)Python:- string + integer problem

Input:- x = int(input()) print ("The number is" + x) And I want the output:-(if input is 1) The number is 1. How can I do it. It is showing that int + str is invalid.

4th Jan 2022, 3:22 AM
๐“๐“ท๐“ผ๐“ฑ๐“ฒ๐“ด๐“ช (Anshika)
๐“๐“ท๐“ผ๐“ฑ๐“ฒ๐“ด๐“ช (Anshika) - avatar
4 Answers
+ 2
๐€๐ง๐ฌ๐ก๐ข๐ค๐š ๐’๐ข๐ง๐ ๐ก Just use comma (,) at place of (+) , it quite simple then other methods. ๐Ÿ˜Š๐Ÿฅฐ๐Ÿ˜Š
4th Jan 2022, 3:00 PM
ร„arush Rajput
+ 4
remove the int() with x. x = input() # x is string & str + str is valid
4th Jan 2022, 3:26 AM
TOLUENE
TOLUENE - avatar
+ 2
Either replace the plus with a comma (in this case python inserts a space) or use "str(x)".
4th Jan 2022, 3:27 AM
Simon Sauter
Simon Sauter - avatar
+ 2
(solved)Python:- string + integer problem Input:- x = int(input()) print ("The number is" +str( x)) And I want the output:-(if input is 1) The number is 1. How can I do it. It is showing that int + str is invalid. Run this code.... It will run ... You can't add a integer with string. For this you have to convert integer into string for this use str() function Menas Print("The number is "+' '+str(x)) if you take integer as a input then you have to convert integer into string then your will not get error ๐€๐ง๐ฌ๐ก๐ข๐ค๐š ๐’๐ข๐ง๐ ๐ก
14th Jan 2022, 3:51 AM
๐‘บ๐‘ฏ๐‘ผ๐‘ฉ๐‘ฏ๐‘จ๐‘ด ๐‘น๐‘จ๐‘ฑ
๐‘บ๐‘ฏ๐‘ผ๐‘ฉ๐‘ฏ๐‘จ๐‘ด ๐‘น๐‘จ๐‘ฑ - avatar