- 1
Connect 2 variables without rewriting fornula
Hi shadoff Let us say: B=2 C=2 A=b+c I need a way that if i write B=3 The value of A automatically becomes 5 instead of 4 without rewriting formula A=B+C
3 odpowiedzi
+ 1
a = 3
b = 2
def adding(x,y):
return x+y
print(adding(a,b))
a=int(input('another number: '))
print(adding(a,b))
+ 1
“The value of A automatically becomes 5 instead of 4 without rewriting formula A=B+C”
b = 2
c = 2
def var_a(b): # func a = b+c
a = b + c
return a
b = 3
print(var_a(b))
b = 7
print(var_a(b)) #thenever you call the function, you get the sum of b and c with the last value of b and c
+ 1
If you change the value of code from the code, directly or indirectly, you have to rewrite the formula again and again when you change the value of b even if it's with function or directly or with loop.If you use a function you mightn't need to write the sum but you have to call the function that does the sum.If you really need that feature, you should take the input from the user not giving in code:
https://code.sololearn.com/ca5a18a269A1
In this code, just give the input of b in separate lines and when you don't need to change input write close.