user662973 - 4 months ago 6x

Python Question

`def minimum (pNum1,pNum2):`

#subprogram here

return ()

inNum = int (input ("Please enter a number. 0 to quit."))

minNum = inNum

maxNum = inNum

while (inNum !=0):

# ===> minNum = # here is where I will call the subprogram.

# ===> maxNum =

# ===> theSum =

inNum = int (input ("Please enter a number. 0 to quit."))

I have attempted to write a function to find the minimum of numbers entered. The user keeps entering numbers until they press 0.

I would like to attempt finding out how to get the maximum and how to add. I do not want to use the built in min/max that Python uses. I have looked on the net and this forum.

Any help is appreciated.

Thank you in advance.

Answer

This is an implementation of a function that finds the minimum of two values:

```
def minimum(pNum1, pNum2):
if pNum1 < pNum2:
return pNum1
else:
return pNum2
```

A program to find the minimum, maximum, and the sum:

```
inNum = int(input("Please enter a number. 0 to quit."))
minNum = inNum
maxNum = inNum
theSum = inNum
while inNum != 0:
inNum = int(input("Please enter a number. 0 to quit."))
if inNum == 0:
break
minNum = minimum(minNum, inNum)
maxNum = maximum(maxNum, inNum)
theSum += inNum
print minNum, maxNum, theSum
```

I will leave it to you to write the `maximum`

function.

Source (Stackoverflow)

Comments