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])
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)
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])
# 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.
# 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)
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))
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.
If you are more comfortable learning through video tutorials then we would recommend that you subscribe to our YouTube channel.
When going through coding examples, it's quite common to have doubts and errors.
If you have doubts about some code examples or are stuck somewhere when trying our code, send us an email at coderzcolumn07@gmail.com. We'll help you or point you in the direction where you can find a solution to your problem.
You can even send us a mail if you are trying something new and need guidance regarding coding. We'll try to respond as soon as possible.
If you want to