-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path37.py
More file actions
24 lines (24 loc) · 737 Bytes
/
37.py
File metadata and controls
24 lines (24 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#Write a Python program that reads 5 numbers into a list and prints the smallest and largest number and their locations in the list. [You are not allowed to use the max(), min(), sort(), sorted() functions here]
x = input("Enter 5 numbers: ").split(',')
g = []
mx = None
xc = 0
mn = None
xm = 0
for i in x:
g.append(int(i))
for i in range(len(g)):
if mx == None:
mx = g[i]
elif mx < g[i]:
mx = g[i]
xc = i
for i in range(len(g)):
if mn == None:
mn = g[i]
elif mn > g[i]:
mn = g[i]
xm = i
print(f"My list: {g}")
print(f"Smallest number in the list is {mn} which was found at index {xm}")
print(f"Largest number in the list is {mx} which was found at index {xc}")