Introduction
Name Karanveer Singh
Class 11th Commerce
Roll no. 12
project Python
Submitted by. Karanveer Singh
Submitted to. Mrs. Rekha
Session 2024-2025
Python Programming
Assignment
Welcome to your Python Programming
Assignment document. In this comprehensive file,
we will explore a series of Python programs
tailored to enhance your coding skills and reinforce
your understanding of fundamental programming
concepts. Each assignment is meticulously crafted to
provide you with practical experience and hands-on
learning opportunities. From calculating averages to
managing dictionaries, these assignments cover a
wide range of topics relevant to Python
programming. Let's dive into the world of coding
excellence.
This document contains the codes for the
Python programming assignments listed below.
1. To find average and grade for given marks.
2. To find sale price of an item with given cost and discount (%).
3. To calculate perimeter/circumference and area of shapes such
triangle, rectangle, square and circle.
4. To calculate Simple and Compound interest.
5.To calculate profit-loss for given Cost and Sell Price.
6.To calculate EMI for Amount, Period and Interest.
7.To calculate tax-GST/Income Tax.
8.To find the largest and smallest numbers in a list.
9.To find the third largest/smallest number in a list.
10.To find the sum of squares of the first 100 natural numbers.
11.To print the first 'n' multiples of given number.
12.To count the number of vowels in user entered string.
13.To print the words starting with a alphabet in a user entered
string.
14.To print number of occurrences of a given alphabet in each
string.
15.Create a dictionary to store names of states and their capitals.
16.Create a dictionary of students to store names and marks
obtained in 5 subjects
17.To print the highest and lowest values in the dictionary.
So codes of this assignment are as follows :-
1) Calculate Average and grade for given marks:
# Program to find average and grade for given marks
marks = [85, 90, 75, 92, 88]
average = sum(marks) / len(marks)
if average >= 90:
grade = 'A'
elif average >= 80:
grade = 'B'
elif average >= 70:
grade = 'C'
else:
grade = 'F'
print("Average:", average)
print("Grade:", grade)
2) Sale Price Calculation:
# Program to find sale price of an item with given cost and
discount
cost_price = 100
discount_percentage = 20
sale_price = cost_price - (cost_price * discount_percentage /
100)
print("Sale Price:", sale_price)
3) Perimeter/Circumference and Area Calculation:
# Program to calculate perimeter/circumference and area of
shapes
import math
# Triangle
a, b, c = 3, 4, 5
triangle_perimeter = a + b + c
s = triangle_perimeter / 2
triangle_area = math.sqrt(s * (s - a) * (s - b) * (s - c))
print("Triangle Perimeter:", triangle_perimeter)
print("Triangle Area:", triangle_area)
# Rectangle
length, width = 6, 4
rectangle_perimeter = 2 * (length + width)
rectangle_area = length * width
print("Rectangle Perimeter:", rectangle_perimeter)
print("Rectangle Area:", rectangle_area)
# Square
side = 5
square_perimeter = 4 * side
square_area = side * side
print("Square Perimeter:", square_perimeter)
print("Square Area:", square_area)
# Circle
radius = 3
circle_circumference = 2 * math.pi * radius
circle_area = math.pi * radius ** 2
print("Circle Circumference:", circle_circumference)
print("Circle Area:", circle_area)
4) Simple and Compound Interest Calculating:
# Program to calculate Simple and Compound interest
principal = 1000
rate = 5
time = 2
simple_interest = (principal * rate * time) / 100
compound_interest = principal * ((1 + rate / 100) ** time - 1)
print("Simple Interest:", simple_interest)
print("Compound Interest:", compound_interest)
5) Profit- Loss Calculation
# Program to calculate profit-loss for given Cost and Sell Price
cost_price = 100
sell_price = 120
profit_loss = sell_price - cost_price
if profit_loss > 0:
print("Profit:", profit_loss)
elif profit_loss < 0:
print("Loss:", -profit_loss)
else:
print("No Profit No Loss")
6) EMI Calculation:
# Program to calculate EMI for Amount, Period and Interest
principal = 10000
period = 12
Interest_rate = 10
r = interest_rate / (12 * 100)
emi = principal * r * ((1 + r) ** period) / (((1 + r) ** period) -
1)
print("EMI:", emi)
7) Tax Calculating:
# Program to calculate tax/GST or income tax
amount = 1000
tax_rate = 5
tax = (amount * tax_rate) / 100
print("Tax:", tax)
8) Largest and Smallest numbers in a List:
# Program to find the largest and smallest numbers in a
list
numbers = [10, 20, 30, 5, 15]
print("Largest Number:", max(numbers))
print("Smallest Number:", min(numbers))
9) Third Largest/Smallest Number in a List:
9# Program to find the third largest/smallest number in a list
numbers = [10, 20, 30, 5, 15]
sorted_numbers = sorted(numbers)
print("Third Largest Number:", sorted_numbers[-3])
print("Third Smallest Number:", sorted_numbers[2])
10) Sum of Squares of the First 100 Natural Numbers:
# Program to find the sum of squares of the first 100 natural
numbers
sum_of_squares = sum([i ** 2 for i in range(1, 101)])
print("Sum of Squares of First 100 Natural Numbers:",
sum_of_squares)
11) To print the first 'n' multiples of given number:
def print_multiples(number, n):
multiples = [number * i for i in range(1, n + 1)]
return multiples
number = 5
n = 10
print("Multiples:", print_multiples(number, n))
12) To Count the number of vowels in user entered string:
def count_vowels(s):
vowels = 'aeiouAEIOU'
return sum(1 for char in s if char in vowels)
user_string = "Hello World"
print("Number of vowels:", count_vowels(user_string))
13) To print the words starting with a specific alphabet in user
entered string:
def words_starting_with(s, alphabet):
words = s.split()
return [word for word in words if
word.startswith(alphabet)]
user_string = "Apple and apricot are amazing"
alphabet = 'a'
print("Words starting with 'a':",
words_starting_with(user_string, alphabet))
14) To print number of occurrences of a given alphabet in each
string:
def count_alphabet_occurrences(strings, alphabet):
return {string: string.count(alphabet) for string in strings}
strings = ["apple", "banana", "cherry"]
alphabet = 'a'
print("Occurrences of 'a':",
count_alphabet_occurrences(strings,alphabet))
15) Create a dictionary to store names of states and their
capitals:
states_and_capitals = {
"California": "Sacramento",
"Texas": "Austin",
"Florida": "Tallahassee",
"New York": "Albany"
}
print("States and Capitals:", states_and_capitals)
16) Create a dictionary of students to store names and marks
obtained in 5 subjects:
students = {
"John": {"Math": 90, "Science": 85, "English": 88,
"History": 76, "Geography": 92},
"Alice": {"Math": 78, "Science": 82, "English": 89,
"History": 91, "Geography": 74},
"Bob": {"Math": 85, "Science": 80, "English": 86,
"History": 79, "Geography": 88}
}
print("Students and Marks:", students)
17) To print the highest and lowest values in the dictionary:
def highest_and_lowest_values(d):
highest = max(devalues())
lowest = min(devalues())
return highest, lowest
# Example usage
student_marks = {"Math": 90, "Science": 85, "English": 88,
"History": 76, "Geography": 92}
highest, lowest = highest_and_lowest_values(student_marks)
print(f"