+ 2
How can we add a number with a string while printing
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}’)
+ 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
+ 6
Thanks everyone...now i got it...:☺😀😀😁
+ 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)
+ 2
print("Your number is " + str(x))
+ 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
0
s
- 1
str (x)
- 1
xz