Q.1 Write a program to calculate and print the simple interest.
p = int(input("Enter the Principal Amount: "))
r = float(input("Enter Rate of Interest (%): "))
t = float(input("Enter Time Period: "))
si = (p * r * t) / 100
print("Simple Interest Amount:", si)
OUTPUT:
Enter the Principal Amount: 50000
Enter Rate of Interest (%): 2
Enter Time Period: 3
Simple Interest Amount: 3000.0
Q.2 Write a program to evaluate (a+b)2, where value of a=5 and b=4.
a = 5
b = 4
c = a*a + 2*a*b + b*b
print("The value of (a+b)² is:", c)
OUTPUT:
The value of (a+b)2is: 81
Q.3 Write a program to check whether the number is Even or Odd.
num = int(input("Enter any number to test whether it is odd
or even: "))
if num % 2 == 0:
print("The number is even")
else:
print("The number is odd")
O/P
Enter any number to test whether it is odd or even: 57
The number is odd
Q.4 Write a program to take input two numbers from user and calculate addition, subtraction,
multiplication and division.
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
print("Enter which operation would you like
to perform?")
ch = input("Enter any of these char for
specific operation +, -, *, / : ")
if ch == '+':
result = num1 + num2
elif ch == '-':
result = num1 - num2
elif ch == '*':
result = num1 * num2
elif ch == '/':
result = num1 / num2
else:
print("Input character is not
recognized!")
result = None
if result is not None:
print(num1, ch, num2, "=", result)
O/P:
Enter First Number: 6
Enter Second Number: 8
Enter which operation would you like to perform?
Enter any of these char for specific operation +, -, *, / : *
6 * 8 = 48
Q.5 Write a program to check whether the age of voter is 18 plus or not.
age = int(input("Enter age: "))
if age >= 18:
print("Eligible for Voting!")
else:
print("Not Eligible for Voting!")
O/P:
Enter age: 43
Eligible for Voting!
Q.6 Write a program to input marks of different subject and calculate the percentage then
print Grades as per the condition below:
Marks Grades
Marks>= 90 A1
Marks>= 80 A2
Marks>= 70 B1
Marks>= 60 B2
Below 60 Wok Hard
sub1 = int(input("Enter marks of first subject: "))
sub2 = int(input("Enter marks of second subject: "))
sub3 = int(input("Enter marks of third subject: "))
sub4 = int(input("Enter marks of fourth subject: "))
sub5 = int(input("Enter marks of fifth subject: "))
avg = (sub1 + sub2 + sub3 + sub4 + sub5) / 5
print("Percentage:", avg)
if avg >= 90:
print("Grade: A1")
elif avg >= 80:
print("Grade: A2")
elif avg >= 70:
print("Grade: B1")
elif avg >= 60:
print("Grade: B2")
else:
print("Work Hard")
O/P:
Enter marks of first subject: 89
Enter marks of second subject: 82
Enter marks of third subject: 82
Enter marks of fourth subject: 75
Enter marks of fifth subject: 94
Percentage: 84.4
Grade: A2
Q.7 Write a program to input two numbers from user and check which number is greater or
equal using nested if.
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
if num1 >= num2:
if num1 == num2:
print("Both numbers are equal.")
else:
print("First number is greater than the second
number.")
else:
print("Second number is greater than the first number.")
O/P:
Enter first number: 56
Enter second number: 43
First number is greater than the second number.
Q.8 Write a program to calculate profit and loss.
cp = float(input("Enter the Cost Price: "))
sp = float(input("Enter the Selling Price: "))
if cp == sp:
print("No Profit No Loss")
elif sp > cp:
print("Profit of", sp - cp)
else:
print("Loss of", cp - sp)
O/P: Enter the Cost Price: 58
Enter the Selling Price: 70
Profit of 12.0
Q.9 Write a program to print back counting from 20 to 1 using while loop and for loop.
# While loop
x = 20
while x > 0:
print(x)
x -= 1
# For loop
for x in range(20, 0, -1):
print(x)
O/P:
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
Q.10 Write a program using for loop which exit the loop when
number is equal to 4.
for i in range(1, 11):
if i == 4:
break
else:
print(i)
O/P:
1
2
3
Q.11 Write a program using for loop which print all the
values from 1 to 20 except the value 8.
for i in range(1, 21):
if i == 8:
continue
else:
print(i)
O/P
1
2
3
4
5
6
7
9
10
11
12
13
14
15
16
17
18
19
20
Q.12 Write a program to create the list
named as number containing the
following elements.
10,20,30,40,50,60,70,80
Now, write the statement to print the following output.
# a. [30,40,50,60,70,80] (Slicing from a[2] to last
element)
A=[10,20,30,40,50,60,70,80]
print(A[2:])
# b. [10,30,50,70] (Slicing from a[0] to end by
Increment)
A=[10,20,30,40,50,60,70,80]
print(A[0:7:2])
# c. [10,20,30,40,50,60,70,80,90] (Add element)
A=[10,20,30,40,50,60,70,80]
[Link](90)
print(“Updated list”,A)
# d. [10,20,30,40,50,60,70] (Remove element)
A=[10,20,30,40,50,60,70,80]
[Link](80)
print(“Updated list”,A)
# e. [10,’Artificial’,30,40,50,’Intelligence’,60,70,80]
(Change the element)
A=[10,20,30,40,50,60,70,80]
A[1]=’Artificial’
A[5]=’Intelligence’
print(“Updated list”,A)
O/P:
[30, 40, 50, 60, 70, 80]
[10, 30, 50, 70]
Updated list: [10, 20, 30, 40, 50, 60, 70, 80, 90]
Updated list: [10, 20, 30, 40, 50, 60, 70, 90]
Updated list: [10, 'Artificial', 30, 40, 50,
'Intelligence', 70, 80]
Q.13
Write a program to create a tuple named as record contains following the value.
101,’Meenakshi’,’10th’, ‘C’
Now, perform the following operation on tuple:
a. Write the statement to display ‘Meenakshi’ and ‘C’
b. Write the statement to convert tuple into list.
tup = (101, 'Meenakshi', '10th', 'C')
# a Write the statement to display ‘Meenakshi’ and ‘C’
print(tup[1])
print(tup[3])
# b Write the statement to convert tuple into list.
mylist = list(tup)
print(mylist)
O/P:
Meenakshi
C
[101, 'Meenakshi', '10th', 'C']
Q.14 Write a program to create sets for the following :
SetA={‘a’,’b’,’c’,’d’}
Set B={‘b’,’e’,’d’,’f’}
SetC={‘x’,’e’,’c’,’h’}
a. Write the statement to join the SetA and SetC.
SetA={‘a’,’b’,’c’,’d’}
SetC={‘x’,’e’,’c’,’h’}
[Link](SetC)
print(SetA)
b. Write the statement to find matching letters between Set B and SetC.
Set B={‘b’,’e’,’d’,’f’}
SetC={‘x’,’e’,’c’,’h’}
SetB.intersection_update(SetC)
print(SetB)
c. Write the statement to find non-matching letters between Set B and
C.
Set B={‘b’,’e’,’d’,’f’}
SetC={‘x’,’e’,’c’,’h’}
SetB. symmetric_difference_update(SetC)
print(SetB)
O/P:
{'a', 'e', 'd', 'x', 'b', 'h', 'c'}
{'e'}
{'x', 'd', 'b', 'f', 'h', 'c'}
Q.15 Create a dictionary named as Car_detail with the given value. Name= Audi Model=Q8
Price=50, 00,000
Now, perform the following operation on it:
a. Write the statement to add item ‘location’ as ‘Noida’.
Dict = {Name: 'Audi', Model: 'Q7', Price: '50,00,000'}
Print(Dict)
b. Write the statement to print the value of model.
Dict = {Name: 'Audi', Model: 'Q7', Price: '50,00,000'}
Print (Dict[1])
c. Write the statement to change the price value by 40,00,000.
Dict = {Name: 'Audi', Model: 'Q7', Price: '50,00,000'}
Dict[2]=’40,00,000’
Print(Dict)
O/P : {'Name': 'Audi', 'Model': 'Q8', 'Price': '50,00,000', 'Location':
'Noida'}
Q8
{'Name': 'Audi', 'Model': 'Q8', 'Price': '40,00,000', 'Location':
'Noida'}