My code:
lst = [int(i) for i in input().split()]
a = max(lst)
b = min(lst)
lst[lst.index(a)], lst[lst.index(b)] = lst[lst.index(b)], lst[lst.index(a)]
print(' '.join([str(i) for i in lst]))
The answer:
a = [int(s) for s in input().split()]
index_of_min = 0
index_of_max = 0
for i in range(1, len(a)):
if a[i] > a[index_of_max]:
index_of_max = i
if a[i] < a[index_of_min]:
index_of_min = i
a[index_of_min], a[index_of_max] = a[index_of_max], a[index_of_min]
print(' '.join([str(i) for i in a]))
I see that there are answers posted to solve this challenge. I am wanting to know why my version does not work.
New contributor
Chubbs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.