def measuregtxx(p, x, y):
if measure() > p:
p = measure()
x = get_pos_x()
y = get_pos_y()
return p, x, y
if measure() > p1:
p1,x1,y1 = measuregtxx(p1,x1,y1)
elif measure() > p2:
p2,x2,y2 = measuregtxx(p2,x2,y2)
elif measure() > p3:
p3,x3,y3 = measuregtxx(p3,x3,y3)
elif measure() > p4:
p4,x4,y4 = measuregtxx(p4,x4,y4)
elif measure() > p5:
p5,x5,y5 = measuregtxx(p5,x5,y5)
#๐ is there a way to condense this more?
28 messages ยท Page 1 of 1 (latest)
@cold ruin
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
measuregtxx might return None
and this code can be shortened, but only if you define the p1,x1,y1 triples as dataclasses in a list or something
measuregtxx does not return None luckily and ill have to try to add lists
i was also thinking maybe a function is kind of useless since i could just do this
if measure() > p1:
p1,x1,y1 = measure(), get_pos_x(), get_pos_y()
elif measure() > p2:
p2,x2,y2 = measure(), get_pos_x(), get_pos_y())
elif measure() > p3:
p3,x3,y3 = measure(), get_pos_x(), get_pos_y()
elif measure() > p4:
p4,x4,y4 = measure(), get_pos_x(), get_pos_y()
elif measure() > p5:
p5,x5,y5 = measure(), get_pos_x(), get_pos_y()
ty for the list idea
if measuregtxx cannot return None, that means the condition inside is never false and pointless
i'm referring to the implicit return None that all functions end with
i might have misunderstood what you said than
i think im still misunderstanding im still new to programming
i know None is the absence of a value
but im still a little confused when it comes to return its a new concept to me atm
def f():
if 1+1 == 3:
return 123```
this function returns None, because all functions end with an implicit `return None` statement
i.e. it is actually this in disguise:py def f(): if 1+1 == 3: return 123 return None
gotcha so if you never tell it to return something it will return None
so for example in your code it will never return 123 because the if statement would never go through
thats cool
def measuregtxx(p, x, y):
if measure() > p:
p = measure()
x = get_pos_x()
y = get_pos_y()
return p, x, y
else return p, x, y
so would this else fix the problem?
def measuregtxx(p, x, y):
if measure() > p:
p = measure()
x = get_pos_x()
y = get_pos_y()
return p, x, y
nvm it would be that
@reef palm
ty for the help and teaching me something new i appreciate it! have a good day
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ is there a way to condense this more?