Questions from 1 to 25 :: PYTHON
1. Write a program to print the following sentences, Hello Everyone and
Welcome to the world of Python.
Program
print("Hello Everyone and Welcome to the world of Python")
Output
Hello Everyone and Welcome to the world of Python
2. Write a program to print to statements ‚Hello World‛ and ‚I am
learning Python‛.
a. Concatenate the strings
b. Split the strings
Program
a='Hello World’
b='I am learning Python’
c=a+" "+b
print(c)
d=c.split()
print(d)
Output
Hello World I am learning Python
['Hello', 'World', 'I', 'am', 'learning', 'Python']
(OR)
string="Hello World \n I am learning python"
print(string)
Output
Hello World
I am learning python
3. Write a program to insert student details – Name, Father’s name, Hall
ticket number, Date of birth, age, Stream of study, College name.
Program
a=input("Enter Name : ")
b = input("Enter Father Name : ")
c =int(input("Enter Hall ticket number : "))
d = input("Enter Date of Birth : ")
e= int(input("Enter Age : "))
f =input("Enter Stream of Study : ")
g =input("Enter College Name : ")
print("**********Student Details are **********")
print("Name: ", a)
print("Father Name : ", b)
print("Hall ticket number : ", c)
print("Date of Birth : ", d)
print("Age : ", e)
print("Stream of Study : ", f)
print("College Name : ", g)
Output
Enter Name : Soumya
Enter Father Name : Mohan
Enter Hall ticket number : 121220405012
Enter Date of Birth : 23-06-2001
Enter Age : 21
Enter Stream of Study : Computer Science
Enter College Name : St.pious X Degree & PG College for Women
********** Student Details are**********
Name: Soumya
Father Name : Mohan
Hall ticket number : 121220405012
Date of Birth : 23-06-2001
Age : 21
Stream of Study : Computer Science
College Name : St.Pious X Degree & PG College for Women
4.Write a program to prepare the list of rainbow colours and print the
second colour in the "Rainbow" list.
Program
rainbow=['red','orange','yellow','green','blue','indigo','violet’]
print(rainbow)
print(rainbow[1])
Output
['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet’]
Orange
5.Write a program to assign two values to the variables a and b and
perform the mathematical operations addition, subtraction,
multiplication, division, square of a number
Program
a= 25
b = 20
print("Addition of a numbers: ", a+b)
print("Subtraction of a numbers : ", a-b)
print("Multiplication of a numbers : ", a*b)
print("Division of a numbers : ", a/b)
print("Square of a number : ", a*a)
Output
Addition of a numbers: 45
Subtraction of a numbers : 5
Multiplication of a numbers : 500
Division of a numbers : 1.25
Square of a number : 625
6. Write a program to assign three values to the variables a, b and c
and perform the operations addition, multiplication, ((a+b)+c), ( a-
(b+c)),(a*(b+c)), (a + (b*c)), (a*(b-c)).
Program
a = 5
b = 4
c = 3
print("Addition of a numbers: ", a+b+c)
print("Multiplication of a numbers : ", a*b*c)
print("(a+b)+c = ", (a+b)+c)
print("a-(b+c) = ",a-(b+c))
print("a*(b+c) = ",a*(b+c))
print("a+(b*c) = ",a+(b*c))
print("a*(b-c) = ",a*(b-c))
Output
Addition of a numbers: 12
Multiplication of a numbers : 60
(a+b)+c = 12
a-(b+c) = -2
a*(b+c) = 35
a+(b*c) = 17
a*(b-c) = 5
7. Write a program to find the maximum and minimum of the given list
of numbers.
8.Write a program to insert two values at random and perform the
operations addition, multiplication, subtraction and division and square
of a number.
Program
a = int(input("Enter First Number: "))
b = int(input("Enter Second Number: "))
print("Addition of a numbers: ", a+b)
print("Subtraction of a numbers : ", a-b)
print("Multiplication of a numbers : ", a*b)
print("Division of a numbers : ", a/b)
print("Square of a number : ", a*a)
Output
Enter First Number: 2
Enter Second Number: 3
Addition of a numbers: 5
Subtraction of a numbers : -1
Multiplication of a numbers : 6
Division of a numbers : 0.6666666666666666
Square of a number : 4
9. Write a program to insert a number and print ‚You entered an even
number‛ if the number is even and ‚You entered an Odd number‛ if the
entered number is odd.
Program
num = int(input("Enter a number: "))
if (num % 2)==0:
print("You picked an even number.")
else:
print("You picked an odd number.")
Output
Enter a number: 23
You picked an odd number.
Enter a number: 42
You picked an even number.
10. Write a program to insert two numbers and print the maximum number.
Program
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
maximum = max(a, b)
print("The maximum number is ",maximum)
Output
Enter the first number: 34
Enter the second number: 56
The maximum number is 56
11.Write a program to form the list of numbers given
[45, 56, 24, 13, 68, 74, 45, 10, 9,65, 87, 46, 54, 100]
and print third, fourth and fifth numbers.
Program
n=[45, 56, 24, 13, 68, 74, 45, 10, 9, 65, 87,46, 54, 100]
print("The given list is ", n)
print(" third number = ", n[2])
print(" fourth number = ", n[3])
print(" fifth number = ", n[4])
Output
The given list is [45, 56, 24, 13, 68, 74, 45, 10, 9, 65, 87, 46,
54, 100]
third number = 24
fourth number = 13
fifth number = 68
12.Write a program to find the length of the list Program
Program
n=len([45, 56, 24, 13, 68, 74, 45, 10, 9, 65, 87,46, 54, 100])
print("The given list is ", n)
print("The length of the list is ",n)
Output
The given list is [45, 56, 24, 13, 68, 74, 45, 10, 9, 65, 87, 46,
54, 100]
The length of the list is 14
13.Write a program to arrange the above list in the ascending and
descending order
Program
n = [44, 56, 42, 31, 11, 23, 78, 89, 9, 0]
print("The list is :")
print(n)
n.sort()
print("Ascending order : ")
print(n)
n.sort(reverse = True)
print("Descending order : ")
print(n)
Output
The list is :
[44, 56, 42, 31, 11, 23, 78, 89, 9, 0]
Ascending order :
[0, 9, 11, 23, 31, 42, 44, 56, 78, 89]
Descending order :
[89, 78, 56, 44, 42, 31, 23, 11, 9, 0]
14. Create a list of items
[100, 100, 400, 200, 300, 500, 600, 700, 100] Write a program to find
how many times a number appeared in the list
Program
list1 = [100, 100, 400, 200, 300, 500, 600, 700, 100]
print(“The given list is:”,list1)
n=int(input("enter the number = "))
x=list1.count(n)
print("The number", n ,"occurs" , x , "times in the list")
Output
The given list is: [100, 100, 400, 200, 300, 500, 600, 700, 100]
enter the number = 100
The number 100 occurs 3 times in the list
15. Let A = [10, 20, 30, 40] Write a program for repeating the list of
elements three times. Use ‚*‛ operator
Program
A =([10, 20, 30, 40])
N=int(input("Enter number of times = "))
r=((A)*N)
print(r)
Output
enter number of times = 4
[10, 20, 30, 40, 10, 20, 30, 40, 10, 20, 30, 40, 10, 20, 30, 40]
16.Write a program to insert eight values in the list and arrange them
in the ascending order
17. Write a program to insert your name, course and marks of different
subjects. Also print the total and average marks
Program
name=input("Enter the name: ")
course=input("Enter the course: ")
a = int(input("Enter the marks of first subject: "))
b = int(input("Enter the marks of second subject: "))
c = int(input("Enter the marks of third subject: "))
total = a+b+c
avg = total/3
print("Name : ",name)
print("Course : ",course)
print("Total marks: ",total)
print("Average marks: ",avg)
Output
Enter the name: Sri
Enter the course: Buss. Anly
Enter the marks of first subject: 46
Enter the marks of second subject: 67
Enter the marks of third subject: 50
Name : Sri
Course : Buss. Anly
Total marks: 163
Average marks: 54.333333333333336
18. Write a program to print the numbers between 100 and 200 separated
by comma
Program
for x in range(100, 201):
print(x, end=",")
Output
100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,1
17,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,13
4,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151
,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,
169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,1
86,187,188,189,190,191,192,193,194,195,196,197,198,199,200,
19. Given L1 = [45,56,24,13,68,74,45,10,9, 65, 87, 46, 54,100] Print the
numbers from 2nd to 6th from L1.
Program
L1=[45,56,24,13,68,74,45,10,9,65,87,46,54,100]
print(“The given list is”,L1)
for i in range(2,7):
print(“The”,I, “term”,L1[i])
output
The given list is: [45, 56, 24, 13, 68, 74, 45, 10, 9, 65, 87, 46,
54, 100]
The 2 term= 24
The 3 term= 13
the 4 term= 68
The 5 term= 74
The 6 term= 45
20.Create a list of numbers and print them in the order using for
statement
Program
a=[‘Apple’, ‘Orange’, ‘Bread’]
for i, item in enumerate(a,1):
print(i, item)
Output
1 Apple
2 Orange
3 Bread
21. Use list comprehension to create a list of all numbers between
1 to 50 that are divisible by 3
Program
mylist = [x for x in range(1, 51) if x % 3 == 0]
print(mylist)
Output
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48]
22. Write a program to insert the length of the side of a square
and Print its area.
Program
s=int(input("Enter the length of the square = "))
area=s*s
print("The area of the square is = ",area)
Output
Enter the length of the square = 5
The area of the square is = 25
23. Write a program to create a list of 10 elements. Then print
the list by adding a new element at the end of the list.
Program
thislist = [2, 4, 6,8,10,12,14,16,18,20]
thislist.append(22)
print(thislist)
Output
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
24. Write a program to create a list of 8 elements. Write a
program to physically reverse the elements in the list
25.Insert three lists with 4 elements in each. Then write a program to
nest the lists
Program
m1 = [1,2,3,4]
m2 = [5,6,7,8]
m3 = [9,10,11,12]
m= [m1,m2,m3]
print("Nested List :",m)
Output
Nested List : [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]