Python Project File PDF
Python Project File PDF
def calculate_average(marks):
total_marks = sum(marks)
average = total_marks / len(marks)
return average
def assign_grade(average):
if average >= 90:
return 'A'
elif 80 <= average < 90:
return 'B'
elif 70 <= average < 80:
return 'C'
elif 60 <= average < 70:
return 'D'
else:
return 'F'
# Calculate average
average = calculate_average(marks)
# Assign grade
grade = assign_grade(average)
# Display results
print(f"\nAverage marks: {average:.2f}")
print(f"Grade: {grade}")
2. To find sale price of an item with given cost and discount (%).
def calculate_sale_price(cost, discount_percentage):
discount_amount = (discount_percentage / 100) * cost
sale_price = cost - discount_amount
return sale_price
# Input cost and discount percentage
cost = float(input("Enter the cost of the item: "))
discount_percentage = float(input("Enter the discount percentage: "))
# Display result
print(f"\nSale Price: ${sale_price:.2f}")
3. To calculate perimeter/circumference and area of shapes such as triangle, rectangle, square and
circle.
import math
def calculate_square_properties(side):
perimeter = 4 * side
def calculate_circle_properties(radius):
if shape == 'triangle':
else:
# Display results
print(f"\nPerimeter/Circumference: {perimeter:.2f}")
print(f"Area: {area:.2f}")
4. To calculate Simple and Compound interest.
return simple_interest
return compound_interest
# Display results
return profit_loss
# Display result
if profit_loss > 0:
print(f"\nProfit: ${profit_loss:.2f}")
print(f"\nLoss: ${abs(profit_loss):.2f}")
else:
return emi
# Calculate EMI
# Display result
return gst_amount
def calculate_income_tax(income):
# You can implement a more sophisticated income tax calculation logic here
return income_tax
if tax_type == 'gst':
tax_amount = calculate_income_tax(income)
else:
def find_largest_smallest(numbers):
if not numbers:
return None, None # Return None for both largest and smallest if the list is empty
largest = number
smallest = number
# Display results
else:
def find_third_largest_smallest(numbers):
unique_numbers.sort()
if len(unique_numbers) < 3:
third_largest = unique_numbers[-3]
third_smallest = unique_numbers[2]
result = find_third_largest_smallest(numbers)
# Display results
10. To find the sum of squares of the first 100 natural numbers.
def sum_of_squares(n):
result = sum_of_squares(100)
# Display result
print(f"The sum of squares of the first 100 natural numbers is: {result}")
multiple = number * i
print_multiples(number, n)
def count_vowels(input_string):
vowels = "aeiouAEIOU"
vowel_count = 0
if char in vowels:
vowel_count += 1
return vowel_count
# Get user input
# Count vowels
vowel_count = count_vowels(user_input)
# Display result
13. To print the words starting with a alphabet in a user entered string.
words = sentence.split()
if filtered_words:
print(word)
else:
# Call the function to print words starting with the specified alphabet
print_words_starting_with_letter(user_sentence, user_letter)
count = string.lower().count(target_alphabet.lower())
occurrences.append(count)
return occurrences
# Count occurrences
# Display results
indian_states_capitals = {
'Assam': 'Dispur',
'Bihar': 'Patna',
'Chhattisgarh': 'Raipur',
'Goa': 'Panaji',
'Gujarat': 'Gandhinagar',
'Haryana': 'Chandigarh',
'Jharkhand': 'Ranchi',
'Karnataka': 'Bengaluru',
'Kerala': 'Thiruvananthapuram',
'Maharashtra': 'Mumbai',
'Manipur': 'Imphal',
'Meghalaya': 'Shillong',
'Mizoram': 'Aizawl',
'Nagaland': 'Kohima',
'Odisha': 'Bhubaneswar',
'Punjab': 'Chandigarh',
'Rajasthan': 'Jaipur',
'Sikkim': 'Gangtok',
'Telangana': 'Hyderabad',
'Tripura': 'Agartala',
'Uttarakhand': 'Dehradun',
state_to_check = 'Karnataka'
16. Create a dictionary of students to store names and marks obtained in 5 subjects.
def create_student_dictionary():
student_dict = {}
num_students = int(input("Enter the number of students: "))
for i in range(num_students):
marks = []
for j in range(5):
marks.append(mark)
student_dict[student_name] = marks
return student_dict
students = create_student_dictionary()
print("\nStudent Dictionary:")
print(f"{student}: {marks}")
def find_highest_lowest(dictionary):
if not dictionary:
print("Dictionary is empty.")
return
min_value = dictionary[min_key]
find_highest_lowest(my_dictionary)