+ 2

How can we add a number with a string while printing

https://code.sololearn.com/cLSmdXSeLoVg/?ref=app

29th May 2019, 3:21 PM
Y AD Ù
Y AD Ù - avatar
9 odpowiedzi
+ 6
If you use a comma instead of ‘+’ code will run: x = int(input()) print("your number is " , x) If you use f-string it looks like this: print(f’Your number is {x}’)
29th May 2019, 3:28 PM
Lothar
Lothar - avatar
+ 6
Well bro Yes , you can't add a number while printing as string can't be concatenated with number. You can make your code like this x = int(input()) print("your number is " , x) Remove that + sign and place a comma to print the number Thanks
29th May 2019, 3:29 PM
Prince PS[Not_Active]
Prince PS[Not_Active] - avatar
+ 6
Thanks everyone...now i got it...:☺😀😀😁
29th May 2019, 3:32 PM
Y AD Ù
Y AD Ù - avatar
+ 3
In Python, you can not 'add' strings and numbers because it's a different data type. Your solution in this case: print("your number is", x)
29th May 2019, 3:28 PM
HonFu
HonFu - avatar
+ 2
print("Your number is " + str(x))
29th May 2019, 3:28 PM
Diego
Diego - avatar
+ 2
you are only supposed to concatenate string types with other string types if you want to output a string therefore you have to convert your “x” var (input) to string in order to do it. You can replace “x” with “str(x)” and see it works
29th May 2019, 3:29 PM
Gabriele Concli
Gabriele Concli - avatar
0
s
29th May 2019, 6:49 PM
زايد الزيد
- 1
str (x)
29th May 2019, 6:51 PM
زايد الزيد
- 1
xz
29th May 2019, 6:52 PM
زايد الزيد