+ 1
Declaring variables and string
I am declaring variables in python. For example, x = 10 y = 20 z = x + y print(z) = his answer is 30. OK But when I change the value of "y", y = 50. x = 10 y = 20 z = x + y print(z) y = 50 z = x + y print(z) they also give me the previous answer that is 30. Is there any error in this code. and 2nd one check my python strings code a = "new whatsapp" b = "group links https://cheetahlinks.com/" c = a + b print(c) Output: new whatsapp group links. Suggestions.
2 odpowiedzi
+ 7
Your addition code executes fine for me. In the second example I get
30
60
Which is expected, as you have two print statements you will get both results.
Your string concatenation is also fine, but you will need a space either as the last character of the first string or the first character of the second, otherwise your output will be "new whatsappgroup links"
+ 5
Lerry343 ,
If you want people to help debug your code, the best way is to save it in the playground and share the link here so we can just click to run it, rather than having to copy and paste it from a comment into the playground and remove the surrounding text in order to run it.
If you can't share a link, at least copy and paste the code from the playground into a comment so we can read the exact whole code intact.
Never retype it by hand because 1, you might introduce new errors, and 2, you might accidentally fix the error you were trying to show.
You said this code prints this.
30
30
x = 10
y = 20
z = x + y
print(z)
y = 50
z = x + y
print(z)
It actually prints this.
30
60
I suspect it's not the original code. I bet this is.
x = 10
y = 20
z = x + y
print(z)
y = 50
print(z)
For the strings, you can also do this.
a = "new whatsapp"
b = "group links
print(a, b)
But why not this?
print("new whatsapp group links")