0% found this document useful (0 votes)
37 views

Question Number 1: Solution:: Import From Import

The document contains code to create a class called MyCollege that defines attributes and methods to calculate density of colleges based on student count and area. It takes input for college details, calculates density and sends email based on density range. The code defines a class with attributes like college code, name, students, area. Methods to input data, calculate density, display details and send email using SMTP client if density is in given ranges. It creates object, takes input and calls methods to display output and send emails if needed.

Uploaded by

Nishan Hamal
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)
37 views

Question Number 1: Solution:: Import From Import

The document contains code to create a class called MyCollege that defines attributes and methods to calculate density of colleges based on student count and area. It takes input for college details, calculates density and sends email based on density range. The code defines a class with attributes like college code, name, students, area. Methods to input data, calculate density, display details and send email using SMTP client if density is in given ranges. It creates object, takes input and calls methods to display output and send emails if needed.

Uploaded by

Nishan Hamal
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

Question number 1:

Solution:

import smtplib
from email.message import EmailMessage

class MyCollege:
    def __init__(self, IUKL_code = 0, college_name = "", total_student = 0,
                 area_of_college = 0, density_of_college = 0):
        self.IUKLCode = IUKL_code
        self.CollegeName = college_name
        self.TotalStudent = total_student
        self.AreaOfCollege = area_of_college
        self.DensityOfCollege = density_of_college

    def CalculateDensity(self):
        density = self.TotalStudent / self.AreaOfCollege

        return density

    def InputInformationOfCollege(self):
        self.IUKLCode = int(input("Enter IUKL Code: "))
        self.CollegeName = input("Enter College Name: ")
        self.TotalStudent = int(input("Enter Total Number Of Student: "))
        self.AreaOfCollege = int(input("Enter Area Of College: "))
        self.DensityOfCollege = self.CalculateDensity()

    def DensityInformation(self):
        print("==============")
        print("Information")
        print("==============")
        print("IUKL ID = " + str(self.IUKLCode))
        print("College Name = " + (self.CollegeName))
        print("Total Student = " + str((self.TotalStudent)))
        print("Area of College = " + str((self.AreaOfCollege)))
        print("Density of College = " + str((self.DensityOfCollege)))
        if self.TotalStudent > 1500 < 5000:
            print("High Presence of Student")
            self.mailsend("[email protected]", "Highly Presence of Student")
        elif self.TotalStudent >= 500 <= 1500:
            print("Average Presence in the College")
            self.mailsend("[email protected]", "average presence in the Colle
ge")
        elif self.TotalStudent < 500:
            print("too less student in the college")
            self.mailsend("[email protected]", "too less student in the college
")

    def mailsend(self, email, subject):
        password = "[email protected]"
        message = EmailMessage()
        contain = "Total Student = " + str(self.TotalStudent) + " CollegeName 
= " + str(
            self.CollegeName) + " IUKLCode = " + str(self.IUKLCode) + " Area o
f college = " + str(
            self.AreaOfCollege) + " Density of college = " + str(self.DensityO
fCollege)
        message.set_content(contain)
        message['Subject'] = subject
        message['From'] = "[email protected]"
        message['To'] = email
        server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
        server.login("[email protected]", password)
        server.send_message(message)
        server.quit()
        print("Email Sent")

college = MyCollege()
college.InputInformationOfCollege()
college.DensityInformation()

Question number 2:

Solution:

ef vowel():
    f = open('question2.txt', 'r')
    lines = f.readlines()
    vowel_count = ''
    for i in lines:
        if i[0] == 'a' or i[0] == 'e' or i[0] == 'i' or i[0] == 'o' or i[0] =
= 'u' or i[0] == 'A' \
                or i[0] == 'E' or i[0] == 'I' or i[0] == 'O' or i[0] == 'U':
            vowel_count += ("'" + i + "'" + "It is start with vowels'\n")
    print(vowel_count)

vowel()

#Output:
'''an apple is tasty
'It is start with vowels'
'elephants are always fat.'It is start with vowels'

PS C:\Users\BISHAL\Desktop\4th_semester\final_exams\AP>'''

Question number 3:

Solution:

You might also like