I need to define a function T(i) which has the same value (say 10) from i=1 to 1=3, and a different value (say 20) at i=4. I wrote the following code,
def T(i):
for i in range(1, 4):
y= 10
return y
if i==4:
y= 20
return y
for i in range(1, 5): print(i,T(i))
Values from i=1 to 1=3 are printed correctly, but the value at i=4 is wrong. Seems like the second argument is not assigned correctly. Please help.
Thanks in advance.
ifblock after theforis unreachable. The firstreturnhands over control to the caller. What exactly are you up to?