Reputation: 31
Once ti == t_open
is satisfied (which is the if statement) how do i continue making it do the if statement and no longer the else statement even though the ti == t_open is no longer satisfied? I tried using continue but it does not work.
import math
def trackflow(f_in, f_out, r, H, h, t_max, t_open):
t = 0.1
vi = 0
hi = 0
ti = 0
while ti < t_max and hi < H and hi >= 0:
if ti == t_open:
v_2 = vi + (f_in - f_out)*t
h_2 = hi + ((f_in - f_out)*t)/(math.pi*r**2)
t_2 = ti + 0.1
print(round(v_2,1))
print(round(h_2,2))
print(round(t_2,1))
continue
else:
f_out = 0
v_2 = vi + (f_in - f_out)*t
h_2 = hi + ((f_in - f_out)*t)/(math.pi*r**2)
t_2 = ti + 0.1
print(round(v_2,1))
print(round(h_2,2))
print(round(t_2,1))
vi = v_2
hi = h_2
ti = t_2
Upvotes: 0
Views: 62
Reputation: 31
is this what you mean i should do?
import math
def trackflow(f_in, f_out, r, H, h, t_max, t_open):
t = 0.1
vi = 0
hi = 0
ti = 0
ti_topen_was_true = False
while ti < t_max and hi < H and hi >= 0:
if ti == t_open:
v_2 = vi + (f_in - f_out)*t
h_2 = hi + ((f_in - f_out)*t)/(math.pi*r**2)
t_2 = ti + 0.1
print(round(v_2,1))
print(round(h_2,2))
print(round(t_2,1))
or ti_topen_was_true
True
else:
f_out = 0
v_2 = vi + (f_in - f_out)*t
h_2 = hi + ((f_in - f_out)*t)/(math.pi*r**2)
t_2 = ti + 0.1
print(round(v_2,1))
print(round(h_2,2))
print(round(t_2,1))
vi = v_2
hi = h_2
ti = t_2
Upvotes: 0
Reputation: 31
does this mean the same as what i wrote above why does it come up with an error
v_2 is not defined?
import math
def trackflow(f_in, f_out, r, H, h, t_max, t_open):
t = 0.1
vi = 0
hi = 0
ti = 0
def tiEqTOpen():
v_2 = vi + (f_in - f_out)*t
h_2 = hi + ((f_in - f_out)*t)/(math.pi*r**2)
t_2 = ti + 0.1
print(round(v_2,1))
print(round(h_2,2))
print(round(t_2,1))
def tiNEqTOpen():
f_out = 0
v_2 = vi + (f_in - f_out)*t
h_2 = hi + ((f_in - f_out)*t)/(math.pi*r**2)
t_2 = ti + 0.1
print(round(v_2,1))
print(round(h_2,2))
print(round(t_2,1))
while ti < t_max and hi < H and hi >= 0:
if ti == t_open:
tiEqTOpen()
else:
tiNEqTOpen()
vi = v_2
hi = h_2
ti = t_2
Upvotes: 0
Reputation: 4219
I don't really know what you're trying to do but I guess you can do something like this
import math
def trackflow(f_in, f_out, r, H, h, t_max, t_open):
t = 0.1
vi = 0
hi = 0
ti = 0
def tiEqTOpen():
v_2 = vi + (f_in - f_out)*t
h_2 = hi + ((f_in - f_out)*t)/(math.pi*r**2)
t_2 = ti + 0.1
print(round(v_2,1))
print(round(h_2,2))
print(round(t_2,1))
def tiNEqTOpen():
f_out = 0
v_2 = vi + (f_in - f_out)*t
h_2 = hi + ((f_in - f_out)*t)/(math.pi*r**2)
t_2 = ti + 0.1
print(round(v_2,1))
print(round(h_2,2))
print(round(t_2,1))
while ti < t_max and hi < H and hi >= 0:
if ti == t_open:
tiEqTOpen()
continue
else:
tiNEqTOpen()
vi = v_2
hi = h_2
ti = t_2
else:
while <the_new_condition>:
<your_logic_using_the_inner_functions_above>
I hope it helps.
Upvotes: 1