注:这是自己跟着慕课嵩天老师的课程写的笔记。笔记若有错误,希望大家批评指正。
#三者最大实例
import math
def MAX1():
num = int(input("共需要比较几个数的大小:"))
vlist = []
for i in range(num):
shunxu = i + 1
x = float(input("请按照第"+str(shunxu)+"输入要比较的数值序列"))
vlist.append(x)
vlist.sort()
print("最大值为",vlist[num-1])
def MAX2():
num = int(input("共需要比较几个数的大小:"))
vlist = []
for i in range(num):
shunxu = i + 1
x = float(input("请按照第"+str(shunxu)+"输入要比较的数值序列"))
vlist.append(x)
MAX = vlist[0]
for i in range(1,num):
if MAX < vlist[i]:
MAX = vlist[i]
print("最大值为",MAX)
def MAX3():
n = eval(input("How many numbers are there?"))
max = eval(input("Enter a number >>"))
for i in range(n-1):
x = eval(input("Enter a number >>"))
if x > max:
max = x
print("The largest value is ",max)
def MAX4():
x1, x2, x3 = eval(input("Please enter three values:"))
print("The largest value is ",max(x1, x2, x3))
def main():
print("-----方法1------")
MAX1()
print("-----方法2------")
MAX2()
print("-----方法3------")
MAX3()
print("-----方法4------")
MAX4()
main()