Python编写程序,实现输入n个整数,输出最大的,并指出是第几个数?

Python编写程序,实现输入n个整数,输出最大的,并指出是第几个数?,第1张

a=list(eval(input(“森迹请输入n个整数”)))

b=max(a)

c=len(a)

for i in range(1,c+1):

if a[i-1]==b:

print("最大的数是此基并%d,是锋粗第%d个数"%(b,i))

#python2下的代码:

test=input('请输入一个数组纳亮:')

temp=sorted(test)

print '从小到大排序得:',temp

print '您输入的数组中,最大的数为腔茄没:%g'%temp[-1]

print '您输入的数组中,第二大大的数为:%g'%temp[-2]

'------------------------------------'

#python3下的代码:

test=input('请输入一个数组:')

temp=[]

for i in test.split(','):

temp.append(int(i))

temp=sorted(temp)

print('从小到大排序得:',temp)

print('您输入伍纳的数组中,最大的数为:%g'%temp[-1])

print('您输入的数组中,第二大大的数为:%g'%temp[-2])

回答会自动过滤缩进扒纤唯,需要按照上图调整语法缩进春培,下方是代码

def num_max():

# 获取 3 个整数的输入

num1 = int(input("请输入竖兄第一个整数:"))

num2 = int(input("请输入第二个整数:"))

num3 = int(input("请输入第三个整数:"))

# 计算最大值

max_num = max(num1, num2, num3)

# 输出最大值

print("最大数是:", max_num)

# 调用函数

num_max()


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12518697.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2025-08-25
下一篇2025-08-25

发表评论

登录后才能评论

评论列表(0条)

    保存