Computer Science, asked by luvkumar3891, 3 months ago

Write a program to find the smallest element in the list

Answers

Answered by anindyaadhikari13
4

Required Answer:-

Question:

  • Write a python program to find the smallest element in the list.

Solution:

This is an easy question. Read this post to get your answer.

This can be done using two ways.

1. Using min() function.

a=[]

n=int(input("How many elements do you want in the list? "))

print("Enter the elements...")

for i in range(0,n):

a.append(int(input("Enter: ")))

print("Smallest element in the list is: ",min(a))

2. Without using min() function.

a=[]

n=int(input("How many elements do you want in the list? "))

print("Enter the elements...")

for i in range(0,n):

a.append(int(input("Enter: ")))

min=a[0]

for i in range(0,n):

if a[i]<min:

min=a[i]

print("Smallest element in the list is: ",min)

Output is attached. It's better to follow the first approach as it's the easiest one.

Attachments:
Answered by Oreki
2

lst = [int(number) for number in input("Enter the elements - ").split( )]

print("Smallest element -", min(lst))

Similar questions