-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Assignment 1: School
School has many Students. Each Student has name, age and roll number. School admits student one at a time. Student is assigned the roll number during admission. School has capacity of 20 students. It cannot admit more students than its capacity. The School gives message "Admissions full. No more seats available". School conducted an exam. Each student's score was equal to roll number plus 50 divided by number of students. Score was stored in Result with roll number of the student. Later the school published the result. The published result was on the following format.
Roll no. | Name | Score
1 | Student name | 321435
Assignment 2: Thing
- Make a class called Thing with no contents and print it. Then, create an object called example from this class and also print it. Are the printed values the same or different?
- Make a new class called Thing2 and assign the value 'abc' to a class attribute called letters. Print letters.
- Make yet another class called Thing3. This time assign the value 'xyz' to an instance (object) attribute called letters. Print letters. Do you need to make an object from the class to do this?
Assignment 3: Element
- Make a class called Element, with instance attributes name, symbol, and number. Create an object of this class with the values 'Hydrogen', 'H' and 1.
- Make a dictionary with these keys and values: 'name':'Hydrogen', 'symbol':'H', 'number':1. Then create an object called hydrogen from class Element using this dictionary.
- For the Element class, define a method called dump() that prints the values of the object's attributes (name, symbol, number). Create the hydrogen object from this new definition and use dump() to print its attributes.
- Call print(hydrogen). In the definition of Element, change the name of method dump to str. Create a new hydrogen object, and call print(hydrogen) again.
- Modify Element to make the attributes name, symbol and number private. Define a getter property for each to return its values.
Assignment 4: Geometry
- Create Line class methods to accept coordinates as a pair of tuples and return the slope and distance of the line.
slope = (y2-y1)/(x2-x1)
distance = square root[(x2-x1)^2 + (y2-y1)^2] - Create Cylinder class with methods volume and surface area taking height and radius as input parameters.
volume = pi * r^2 * h
surface area = (2pirh) + (2pi*r^2)
Assignment 5: Bank Account
Create a bank account class that has two attributes-owner, balance;
and two methods - deposit, withdraw.
Additionally, the withdrawals may not exceed the available balance.
Instantiate the class, make deposits and withdrawals, and test to make sure the account cannot be overdrawn.