+ 2

i have tried can someone help

ummm……. ok so here: x=5 y= x+3 y= int (str(y) +”2”) print(y)

20th Aug 2021, 5:04 PM
Lila Colon
5 odpowiedzi
+ 9
i think the interpreter couldn't recognize those quotation marks. maybe try this quotation mark "
20th Aug 2021, 5:08 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 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)
20th Aug 2021, 5:16 PM
David García Prados
+ 1
output should be 82 y equals 8 then 8 and 2 are concatenated and converted to int.
20th Aug 2021, 5:10 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 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
21st Aug 2021, 3:47 AM
A͢J
A͢J - avatar
0
Since print() always outputs a string, your third line could just be y = str(y) + "2"
21st Aug 2021, 8:47 AM
David Ashton
David Ashton - avatar