Assignment 1
Assignment 1
SEMESTER – II
BCA1211C08 : Object Oriented Programming
Date : 10/01/2023
1. Create a dictionary of Cars and print the car company of a specific model.
cars={
‘hyundai’ : “i10”,
‘maruti’ : “swift”,
‘honda’ : “city”
}
Print(‘Cars information:’, cars)
Cars.update({‘honda’ : “jazz”}) or cars[‘honda’]=’jazz’
Print(‘Cars information:’, cars) #after appending
2. Write a program to evaluate an expression entered by the user. Also solve that manually and
verify your result with the evaluated one.
3. Write a program to input student’s name, age and percentage in single input() and print the
result.
name, age, marks = input("Enter your Name, Age, Percentage separated by space
").split()
print("\n")
print("User Details: ", name, age, percentage)
4. Write a program to input name, class and marks in five subjects of a student in single input() and
print the percentage of the student.
Most of the time, we need to format output instead of merely printing space-
separated values. For example, we want to display the string left-justified or in the
center. We want to show the number in various formats.
str.format(*args, **kwargs)
The str is the string on which the format method is called. It can contain text or
replacement fields delimited by braces {}.
Each replacement field contains either the numeric index of a positional argument
present in the format method or the name of a keyword argument.
The format method returns a formatted string as an output. Each replacement field
gets replaced with the actual string value of the corresponding argument present
in the format method. i.e., args.
Here {0} and {1} is the numeric index of a positional argument present in the format
method. i.e., {0} = Ault and {1} = Kelly. Anything that not enclosed in braces {} is
considered a plain literal text.
6. Write a program to print names of 5 Planets using {} and format function by using index.
7. Write a Python program to create a Student class
a. Add documentation comments within class as and when required.
b. Add one no arguments constructor which prints some message.
c. Add method studinfo() inside class.Include parameters like rollno,name,contactnum in
method definition.
d. Create three object reference variables of it.
e. Call method and constructor.
8. Write a Python program to create an Employee class
a. Add one constructor which has name, empno, empdept as parameters.
b. Create object reference variable of Employee class
9. Write a Python program to create a Test class.
a. Add factorial() method to print factorials of all the numbers between 1 to n using
recursion. n is taken as the input from the user
b. Call factorial() method.
Every object in Python has a property that is indicated by the symbol __dict__.
Furthermore, this object has every property that has been specified for it. Another
name for __dict__ is mappingproxy object. We can use the dictionary via applying the
__dict__ property to a class object.
# calling displayit function
flower.displayit()
# calling the attribute __dict__ on flower
# object and making it print it
print(flower.__dict__)
Output:
i) Class Test:
def __init__(self):
t1=Test()
t2=Test()
Test.a=888
Test.b=999
Print(‘t1:’ , t1.a,t1.b)
Print(‘t2:’ , t2.a,t2.b)
def __init__(self):
def m1(self):
self.a=888
self.b=999
t1=Test()
t2=Test()
t1.m1()
Print(‘t1:’ , t1.a,t1.b)
Print(‘t2:’ , t2.a,t2.b)
def __init__(self):
@classmethod
def m1(cls):
cls.a=888
cls.b=999
t1=Test()
t2=Test()
t1.m1()
Print(‘t1:’ , t1.a,t1.b)
Print(‘t2:’ , t2.a,t2.b)