python编程,实现输入n个整数,输出其中最大的数,并指出是第几个数
时间: 2023-05-24 17:07:26 浏览: 88
# 输入n个整数
n = int(input("请输入要输入的整数的个数:"))
lst = []
for i in range(n):
num = int(input("请输入第{}个整数:".format(i+1)))
lst.append(num)
# 查找最大值并输出
max_num = max(lst)
index = lst.index(max_num) + 1
print("最大的数是{},是第{}个数。".format(max_num, index))
相关问题
python编程,实现输入n个整数,输出其中最大的数,并指出是第几个数,用循环
n = int(input("请输入整数的个数:"))
max_num = float("-inf")
max_index = 1
for i in range(n):
num = int(input("请输入第%d个整数:" %(i+1)))
if num > max_num:
max_num = num
max_index = i+1
print("最大的数是%d,是第%d个数。" %(max_num, max_index))
用python编程,输入一个整数,求该整数上各位数上是否包含5,若有,从低到高的顺序输出第几位,若没有则输出-1
请稍等,我提交代码片段:
```
num = input("请输入一个整数:")
i = 1
flag = False
for digit in num:
if digit == '5':
print(i)
flag = True
i += 1
if not flag:
print("-1")
```
请您运行以上代码片段,输入一个整数,它将输出该整数中是否包含数字 5 以及每个数字 5 在数字中的位置。如果没有数字 5,则输出 -1。注意:代码中使用了 Python 3 的新特性 input() 函数。
阅读全文
相关推荐
















