help me out with this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

help me out with this code

x=6 y=2 print("x+y") I want 8 to be displayed on screen instead of x+y https://code.sololearn.com/c9ESG2JPI9Ll/?ref=app

15th May 2023, 5:41 AM
Brother Bot
Brother Bot - avatar
35 Answers
+ 17
print(x + y) double quote is for string
15th May 2023, 5:42 AM
A͢J
A͢J - avatar
+ 7
Brother Bot When you print anything inside quotes it becomes string.That's why it is printing x+y instead of 8. If you want 8 to be printed just print x+y
15th May 2023, 8:51 AM
Vibhor
Vibhor - avatar
+ 6
Brother Bot In Class = x +y Class is considered as a variable with the value containing the value of x+y i.e. 8 so now printing variable name class is going to print it's value.So it's correct. Just don't use Quotes it will consider anything inside it as a string.
15th May 2023, 8:55 AM
Vibhor
Vibhor - avatar
+ 5
thanks what about this? x=6 y=2 class="x+y" print(class)
15th May 2023, 5:50 AM
Brother Bot
Brother Bot - avatar
+ 5
Never and never use a keyword for naming a variable. Use other name like num or addition
15th May 2023, 6:00 AM
Ugulberto Sánchez
Ugulberto Sánchez - avatar
+ 5
Brother Bot That's why I have written Class as C capitals as variable. you can't use buit-in function as variable names
15th May 2023, 9:24 AM
Vibhor
Vibhor - avatar
+ 5
A͢J I checked it with an online checker and it answered that is was human text
15th May 2023, 4:52 PM
Ugulberto Sánchez
Ugulberto Sánchez - avatar
+ 4
Brother Bot or: _class = x + y
15th May 2023, 8:52 AM
Ugulberto Sánchez
Ugulberto Sánchez - avatar
+ 3
Brother Bot that is better, yeah
15th May 2023, 6:32 AM
Ugulberto Sánchez
Ugulberto Sánchez - avatar
+ 3
Brother Bot "x+y" and x+y is not same, bro
15th May 2023, 7:06 AM
Fꫀⲅძ᥆͟ᥙ᥉᯽
Fꫀⲅძ᥆͟ᥙ᥉᯽ - avatar
+ 3
Dragon RB Don't post CHAT GPT answer.
15th May 2023, 4:08 PM
A͢J
A͢J - avatar
+ 3
Remove the quotation mark Because if yoU use quotaion mark(" ") it will read it as a string so make it like this: x = 6 y = 2 print(x+y)
15th May 2023, 5:57 PM
ᎧᎮ ᭄𝓗𝓪𝓬𝓴𝓮𝓻꧂
ᎧᎮ ᭄𝓗𝓪𝓬𝓴𝓮𝓻꧂ - avatar
+ 2
Nope, now class is the string "x+y". Get rid of those quotes and it'll work though
15th May 2023, 5:51 AM
Orin Cook
Orin Cook - avatar
+ 2
Dragon RB That is good if it is your own answer but explanation looks like that.
15th May 2023, 4:37 PM
A͢J
A͢J - avatar
+ 2
x=6 y=2 sum=(x+y) print(sum) #bro use "sum" function for addition
16th May 2023, 4:31 PM
RAJ SONI😈😈
RAJ SONI😈😈 - avatar
+ 2
RAJ SONI😈😈 Don't give wrong answer in your answer sum is a variable And a inbuilt method can't be a variable
16th May 2023, 5:49 PM
A͢J
A͢J - avatar
+ 1
thanks a lot Ugulberto how do I know the list of keywords which I have to avoid while naming a variable.
15th May 2023, 6:05 AM
Brother Bot
Brother Bot - avatar
+ 1
thanks I got the list of 33 keywords
15th May 2023, 6:09 AM
Brother Bot
Brother Bot - avatar
+ 1
i can write it as x=6 y=2 Class=x+y print(Class)
15th May 2023, 6:12 AM
Brother Bot
Brother Bot - avatar
+ 1
Print(x+y) is correct
15th May 2023, 2:12 PM
M Tork
M Tork - avatar