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."))
我试图编写一个函数来查找输入的最小数字。用户一直输入数字,直到他们按0。
我想尝试找出如何获得最大值以及如何添加。我不想使用Python使用的内置min / max。我看过网络和这个论坛。
感谢任何帮助。
提前谢谢你。
答案 0 :(得分:0)
目前尚不清楚为什么要这样做。 您可以测试哪个变量是较低的:
def minimum (pNum1,pNum2):
if pNum1 < pNum2:
return pNum1
else:
return pNum2
答案 1 :(得分:0)
这是一个函数的实现,它找到最少两个值:
def minimum(pNum1, pNum2):
if pNum1 < pNum2:
return pNum1
else:
return pNum2
找到最小值,最大值和总和的程序:
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
我会留给你写maximum
函数。