class new_():
def __init__(self):
self.std_=20000
def new1 (self):
if (0<i<=600000):
s=10
elif (800001<i<=1300000):
s=20
i=1000000
for i in range (0,i,100000):
data=new()
data.new1()
s+=s #not able to call the variable inside the if/elif function
print(s)
#how to call the variable inside the class or function
#I want to add "s" each and every 100000 interval
What are you trying to do? Your example makes no sense.
Given your code, my first suggestion is have new1 return the value of s using return s.
Or should s be an instance variable? self.s = 20 and use data.s to get the value.
Or should s be a class variable, or a global? Should new1() be a standalone function? I don't see any reference to new_ or any instances of new_.
How best to implement getting s depends a lot on what you want to do with s and what s means.
Lets get the function working first!
Does this function do something like what you want?
Keep the numbers small to start with for better oversight, all those zeroes make me dizzy!
def do_stuff(num):
s = num
t = 0
for i in range (0,10):
if i <= 4:
s +=10
elif i > 4:
s += 20
t = t + s
print(f's = {s}')
print(f't = {t}')
return s,t
answer = do_stuff(0) # returns (150, 700)
I think a function usually should return some value, so put a return in there.
(Feb-09-2025, 08:09 AM)Pedroski55 Wrote: [ -> ]Lets get the function working first!
Does this function do something like what you want?
Keep the numbers small to start with for better oversight, all those zeroes make me dizzy!
def do_stuff(num):
s = num
t = 0
for i in range (0,10):
if i <= 4:
s +=10
elif i > 4:
s += 20
t = t + s
print(f's = {s}')
print(f't = {t}')
return s,t
answer = do_stuff(0) # returns (150, 700)
I think a function usually should return some value, so put a return in there.
Understood now. thank you. I solved my issue.