a = 10
b = 5
s = a * b
def test(x):
x = a * a * b
test(s)
print(s)
Why isn't the s equal to 500? Why the function didn't work?
a = 10
b = 5
s = a * b
def test(x):
x = a * a * b
test(s)
print(s)
Why isn't the s equal to 500? Why the function didn't work?
This is because you are printing the variable s
not x
. To change the value of s to 500:
a = 10
b = 5
s = a * b
def test(s):
s = s * a # The value of s will be 500
print(s) #This will print 500.
test(s) # Here you are passing the value of `s` which is 50 to the test function