- Program to Find the Largest Number in a List
- Program to Merge Two Lists and Sort it
- Program to Find the Second Largest Number in a List
- Program To Get A Sublist In Python Using Slicing
- Program to Check if a Number is Odd or Even
- Program to Check Prime Number

In [1]:

```
a=[]
n=int(input("Enter number of elements:"))
for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
a.sort()
print("Largest element is:",a[n-1])
```

- The user is asked to enter the value of the element and store it in the variable.
- Then the user will be asked to enter the elements of the list one by one using a for loop and store it in a list.
- Make sure the list should then be sorted.
- Then the last element of the list is printed which is also the largest element of the list.

In [3]:

```
a=[]
c=[]
n1=int(input("Enter number of elements:"))
for i in range(1,n1+1):
b=int(input("Enter element:"))
a.append(b)
n2=int(input("Enter number of elements:"))
for i in range(1,n2+1):
d=int(input("Enter element:"))
c.append(d)
new=a+c
new.sort()
print("Sorted list is:",new)
```

In [4]:

```
a=[]
n=int(input("Enter number of elements:"))
for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
a.sort()
print("Second largest element is:",a[n-2])
```

- In this program, the user will be asked to enter the number of elements and store it in a variable.
- User must then enter the elements of the list one by one using a for loop and store it in a list.
- Again you must makes sure that the List should then be sorted.
- Then the last element of the list is printed which is also the largest element of the list.

In [5]:

```
# list of numbers
n_list = [1, 2, 3, 4, 5, 6, 7]
# list items from 2nd to 3rd
print(n_list[1:3])
# list items from beginning to 3rd
print(n_list[:3])
# list items from 4th to end of list
print(n_list[3:])
# Whole list
print(n_list[:])
```

Here, in the above program you can see that from a larger list we have created sublist by providing the elements. When you enter the starting value and ending value, it will display the values that come in that range.

In [7]:

```
# list of numbers
n_list = [1, 2, 3, 4]
# Changing the value of 3rd item
n_list[2] = 100
# list: [1, 2, 100, 4]
print(n_list)
# Changing the values of 2nd to fourth items
n_list[1:4] = [11, 22, 33]
# list: [1, 11, 22, 33]
print(n_list)
```

In [8]:

```
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even number".format(num))
else:
print("{0} is Odd number".format(num))
```

In [9]:

```
num = int(input("Enter a number: "))
if num > 1:
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
else:
print(num,"is not a prime number")
```

A prime number is a natural number greater than 1 and having no positive divisor other than 1 and itself.

The user is asked to enter the value and the program will check whether the number is prime or not.

**Thank You** for visiting our website. If you like our work, please support us so that we can keep on creating new tutorials/blogs on interesting topics (like AI, ML, Data Science, Python, Digital Marketing, SEO, etc.) that can help people learn new things faster. You can support us by clicking on the **Coffee** button at the bottom right corner. We would appreciate even if you can give a thumbs-up to our article in the comments section below.

If you want to

- provide some suggestions on topic
- share your views
- include some details in tutorial
- suggest some new topics on which we should create tutorials/blogs