Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
24 views

Assingment On:: #Assignment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Assingment On:: #Assignment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assingment on:

1.Calcuting Result(GPA) using Python Inheritance method.


2.Creating simple calculator by Python program.
Submitted By:
Ramisa Maliha
ID: BPP-000512
Batch:BPP-0005
Submitted To:
Rubya Shaharin
Assistant Professor
Department of computer Science and Engineering
Jatiya Kabi Kazi Nazrul Islam University.

#ASSIGNMENT

1.Calculating Result (GPA) Using Python Inheritance

class Student:
def __init__(self, name, student_id):
self.name = name
self.student_id = student_id

def display_student_info(self):
print(f"Student Name: {self.name}")
print(f"Student ID: {self.student_id}")

class Result(Student):
def __init__(self, name, student_id, grades):
super().__init__(name, student_id)
self.grades = grades

def calculate_gpa(self):
# Assign a grade point for each grade and calculate GPA
grade_points = {'A+': 4.0, 'A': 3.75, 'A-': 3.5, 'B+': 3.25, 'B': 3.0, 'C+': 2.75, 'C': 2.5, 'D': 2.0, 'F':
0}
total_points = 0
for grade in self.grades:
total_points += grade_points.get(grade, 0)
gpa = total_points / len(self.grades) if self.grades else 0
return round(gpa, 2)

def display_result(self):
self.display_student_info()
print(f"GPA: {self.calculate_gpa()}")

# Example usage
student = Result("Alex Smith", "S1234", ['A', 'B+', 'A-', 'C', 'B'])
student.display_result()

2.Creating imple calculator by python program.

# Simple Calculator in Python

# Function to add two numbers


def add(x, y):
return x + y

# Function to subtract two numbers


def subtract(x, y):
return x - y

# Function to multiply two numbers


def multiply(x, y):
return x * y

# Function to divide two numbers


def divide(x, y):
if y != 0:
return x / y
else:
return "Cannot divide by zero!"

# Display menu to the user


print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")

# Take input from the user


choice = input("Enter choice (1/2/3/4): ")

# Check if the choice is valid


if choice in ['1', '2', '3', '4']:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

if choice == '1':
print(f"{num1} + {num2} = {add(num1, num2)}")

elif choice == '2':


print(f"{num1} - {num2} = {subtract(num1, num2)}")

elif choice == '3':


print(f"{num1} * {num2} = {multiply(num1, num2)}")

elif choice == '4':


print(f"{num1} / {num2} = {divide(num1, num2)}")

else:
print("Invalid input")

You might also like