Middle value using python 3 -
updated
a = int(input("give value: ")) b = int(input("give value: ")) c = int(input("give value: ")) def middle(a, b ,c) : m = min(a,b,c) m = max(a,b,c) homecoming a+b+c-m-m
this im at. takes numbers data. how display middle one?! sorry i'm terrible @ this. way in on head on intro course. @commusoft @zorg @paxdiablo , else
you should set colon (:
) on first line (def
) well.
this works online python environment:
def input(a, b, c) : if <= b <= c or c <= b <= : homecoming b elif b <= <= c or c <= <= b : homecoming else: homecoming c
furthermore more advisable create utilize of min , max guess. min , max straight supported cpu , there implementations avoid branching (if-then-else's):
def input(a, b, c) : m = min(a,b,c) m = max(a,b,c) homecoming a+b+c-m-m
or:
def input(a, b, c) : homecoming min(max(a,b),max(b,c),max(a,c))
the lastly 1 numerically stable.
in cases if-then-else clauses should avoided. cut down amount of pipelining although in interpreted languages might not increment performance.
based on comments, guess want write interactive program. can done like:
def middle(a, b, c) : #defining method homecoming min(max(a,b),max(b,c),max(a,c)) = int(input("give value: ")) b = int(input("give b value: ")) c = int(input("give c value: ")) print("the requested value ") print(middle(a,b,c)) #calling method
defining method never result in python using method. a
, b
, c
in def
block not a
, b
, c
in rest of program. these "other variables happen have same name". in order call method. write methods name , between brackets parameters wish phone call method.
python python-3.x median python-3.4
No comments:
Post a Comment