+ 2
i have tried can someone help
ummm……. ok so here: x=5 y= x+3 y= int (str(y) +”2”) print(y)
5 Antworten
+ 9
i think the interpreter couldn't recognize those quotation marks. maybe try this quotation mark "
+ 4
The problem are quotation marks of "2"
This works and prints the expected 82
x=5
y= x+3
y= int (str(y) +"2")
print(y)
+ 1
output should be 82
y equals 8
then 8 and 2 are concatenated and converted to int.
+ 1
Lila Colon
It's simple. Anything inside single or double quotes in python will be String so here "2" is string.
Now you can't add integer with string directly in python. It will give "TypeError" so here we converted integer to string with str function.
Now str(y) will be concat with "2" so y was 8 (5 + 3) now this 8 will be concat with "2" so result will be 82.
Now the type of 82 would be string so to convert in integer we used int function
https://code.sololearn.com/ccP9laNsOIjx/?ref=app
0
Since print() always outputs a string, your third line could just be
y = str(y) + "2"