1.
Write Python Program to Calculate the Area of a
Triangle
Source Code:
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
area = 0.5 * base * height
print("The area of the triangle is:", area)
Screenshot of Output:
2. WAP to calculate Simple Interest
Source Code:
P = float(input("Enter the principal amount: "))
R = float(input("Enter the rate of interest: "))
T = float(input("Enter the time (in years): "))
SI = (P * R * T) / 100
print("The Simple Interest is:", SI)
Screenshot of Output:
3. WAP to display cube of a given number
Source Code:
num = int(input("Enter a number: "))
cube = num ** 3
print("The cube of", num, "is:", cube)
Screenshot of Output:
4. WAP to display a mathematical table of a given
number.
Source Code:
num = int(input("Enter a number: "))
print(f"\nMultiplication Table of {num}:")
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
Screenshot Of Output:
5. WAP to display whether a given number is even or odd.
Source Code:
num = int(input("Enter a number: "))
if num % 2 == 0:
print(num, "is Even")
else:
print(num, "is Odd")
Screenshot of Output:
6. WAP to calculate profit or loss.
Source Code:
cp = float(input("Enter the Cost Price: "))
sp = float(input("Enter the Selling Price: "))
if sp > cp:
profit = sp - cp
print("Profit =", profit)
elif cp > sp:
loss = cp - sp
print("Loss =", loss)
else:
print("No Profit, No Loss")
Screenshot of Output:
7. WAP to create a
a. list by your name and add 15 elements (mix of whole
no., decimals and alpha numeric)
b. add 2 more elements using append method
c. delete 3 elements from the list
d. add 12,14,16 at 5th, 6th and 9th indexed position.
Source Code:
yashita = [10, 25.5, "A12", 99, 45.6, "X9", 77, 3.14, "Hello1", 88,
100.5, "B22", 9, 2.5, "Z3"]
print("Original list:", yashita)
[Link](200)
[Link]("NewItem")
print("After appending 2 elements:", yashita)
del yashita[2]
del yashita[5]
del yashita[8]
print("After deleting 3 elements:", yashita)
[Link](5, 12)
[Link](6, 14)
[Link](9, 16)
print("Final list:", yashita)
Screenshot of Output:
8. WAP to check if a person is eligible to vote or not.
Source Code:
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
Screenshot of Output:
9. WAP to print first 10 natural numbers using for loop
Source Code:
print("First 10 natural numbers are:")
for i in range(1, 11): # range starts from 1 and goes till 10
print(i)
Screenshot of Output:
10. WAP to print odd numbers between 1 and 20 using for
loop
Source Code:
print("Odd numbers between 1 and 20 are:")
for i in range(1, 21):
if i % 2 != 0:
print(i)
Screenshot of Output:
11. Wap to display squares of all numbers from 1 to 50
using for loop
Source Code:
print("Squares of numbers from 1 to 50:")
for i in range(1, 51):
square = i ** 2
print(f"{i}^2 = {square}")
Screenshot of Output:
12. WAP to reverse a list.
Source Code:
my_list = [1, 2, 3, 4, 5, 6]
print("Original list:", my_list)
my_list.reverse()
print("Reversed list (using reverse()):", my_list)
Screenshot of Output:
13. WAP to Perform Basic Arithmetic Operations on
arrays using NumPy library.
a. Adding two arrays
b. Subtracting two arrays
c. Product of two arrays
Source Code:
import numpy as np
array1 = [Link]([1, 2, 3, 4, 5])
array2 = [Link]([5, 4, 3, 2, 1])
addition = array1 + array2
print("Addition of two arrays:", addition)
subtraction = array1 - array2
print("Subtraction of two arrays:", subtraction)
product = array1 * array2 print("Product of two arrays:", product)
Screenshot of Output:
14. Create a bar chart using Matplotlib library to compare
student’s marks: Student_names = [“Pooja”, “Neha”,
“Riya”, “Kavya”, “Rani”, “Ravi”, “Kajal”] Student_marks
= [45, 55, 55, 44, 78, 90,60]
Source Code:
import [Link] as plt
Student_names = ["Pooja", "Neha", "Riya", "Kavya", "Rani",
"Ravi", "Kajal"]
Student_marks = [45, 55, 65, 70, 60, 75, 50]
[Link](Student_names, Student_marks, color='skyblue')
[Link]("Students' Marks Comparison")
[Link]("Students") [Link]("Marks")
[Link]()
Screenshot of Output:
15. Create a Customer Waiting Time Histogram (with
colour magenta) using Matplotlib library:
Frequency = [5, 6, 1, 11, 22, 23, 6, 23, 16, 17, 14, 15, 23,
18, 19]
Minutes = [5, 10, 15, 20, 25]
Source Code:
import [Link] as plt
Frequency = [5, 6, 1, 11, 22, 23, 6, 23, 16, 17, 14, 15, 23, 18, 19]
bins = range(5, 5 + 5*len(Frequency), 5) # [5, 10, 15, ..., 75]
[Link](bins, Frequency, width=5, color='magenta',
edgecolor='black', align='edge')
[Link]("Customer Waiting Time Histogram")
[Link]("Waiting Time (minutes)")
[Link]("Frequency")
[Link]()
Screenshot of Output:
------------------------------------------------------------------------------------------------------------
----