why cant i get this to display the middle number/value?

0 votes
asked Feb 15, 2018 by anonymous 1 flag
middle=0

def entervalue():
    value=input(int("enter a number:"))
    return value
def calcMiddle(v1,v2,v3):

    if v1>v2 and v1<v3:
        middle=middle+v1
    if v2>v1 and v2<v3:
        middle=middle+v2
    if v3>v2 and v3<v1:
        middle=middle+v3
    if v3<v1 and v3>v2:
        return middle

def showresult():
    print("the middle number is:",middle)

number=entervalue()
mid_num=calcMiddle(value)
result=showresult()

1 Answer

0 votes
answered Feb 15, 2018 by anonymous
mid_num=0

def entervalue():
  value=int(input("enter a number:"))
  return value
  
def calcMiddle(v1,v2,v3):
  middle=0;
  print ("v1 = %d\nv2 = %d\nv3 = %d" %(v1,v2,v3))
  if v1>v2 and v1<v3:
    middle=middle + v1
  if v2>v1 and v2<v3:
    middle=middle + v2
  if v3>v2 and v3<v1:
    middle=middle + v3
  return middle

def showresult():
  print("\nthe middle number is:",mid_num)

print("Input 3 numbers")
mid_num=calcMiddle(entervalue(), entervalue(), entervalue())
result=showresult()
commented Feb 15, 2018 by anonymous
this solution has some problem
so try this updated one.


mid_num=0

def entervalue():
  value=int(input("enter a number:"))
  return value
  
def calcMiddle(v1,v2,v3):
  middle=0;
  print ("v1 = %d\nv2 = %d\nv3 = %d" %(v1,v2,v3))
  if ((v1>v2 and v1<v3) or  (v1<v2 and v1>v3)):
    middle=middle + v1
  if ((v2<v3 and v2>v1) or (v2>v3 and v2<v1)):
    middle=middle + v2
  if((v3<v1 and v3>v2) or (v3>v1 and v3<v2)):
    middle=middle + v3
  return middle

def showresult():
  print("\nthe middle number is:",mid_num)


print("\nInput 3 numbers")
mid_num=calcMiddle(entervalue(), entervalue(), entervalue())
result=showresult()
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...