Unlock the Potential of Programming: Coding for Solutions

Wednesday, January 26, 2022

02lecture

User i/p

In [2]:
student = input("Student Name: ")
Student Name: Zain
In [3]:
car = input("Car name: ")
Car name: Ford
In [4]:
Total_marks = input("Total marks: ")
Total marks: 98
In [5]:
Patient_Name = input("Patient Name: ")
Patient Name: Mike
In [6]:
height_inches = input("height_inches: ")
height_inches: 98.5
In [7]:
weight_pounds = input("weight_pounds: ")
weight_pounds: 18.2
In [8]:
print("NMHU")
print("CS")
NMHU
CS
In [9]:
# print in a signle line
print("NMHU",end = ' ')
print("CS")
NMHU CS
In [10]:
print("University: NMHU")
print("Department: CS")
University: NMHU
Department: CS
In [11]:
print("University: NMHU" ,end = ' ')
print("Department: CS")
University: NMHU Department: CS

task

class ----> PatientData

Attributes
1-name
2-height_inches
3-weight_pounds


result:

Patient Name: Mike  ---->>> user i/p 

Patient Data(before):
0 in: 0 lbs:

Patient Data(after):
height_inches :71   ------>>> user i/p
weight_pounds:175   ------->>> user i/p
71 in: 175 lbs    
In [12]:
class PatientData:
    def __init__(self):
        self.name = ""
        self.height_inches =0
        self.weight_pounds =0
        
patient = PatientData()  # object

Patient_Name = input("Patient Name: ")

print("\nPatient Data(before):")
print(patient.height_inches ,"in: ",end = " ")
print(patient.weight_pounds,"lbs: ")


print("\nPatient Data(after):")
patient.height_inches=input("height_inches: ")
patient.weight_pounds= input("weight_pounds:")

print(patient.height_inches ,"in: ",end = " ")
print(patient.weight_pounds,"lbs: ")
Patient Name: Mike

Patient Data(before):
0 in:  0 lbs: 

Patient Data(after):
height_inches: 71
weight_pounds:175
71 in:  175 lbs: 

task

========= information of patient_1 ==============================

Patient Name: Mike

Patient Data(before):
0 in:  0 lbs: 

Patient Data(after):
height_inches: 45
weight_pounds:25
45 in:  25 lbs: 



========= information of patient_2 ==============================   

Patient Name: Zain

Patient Data(before):
0 in:  0 lbs: 

Patient Data(after):
height_inches: 55
weight_pounds:35
55 in:  35 lbs:


========= information of patient_3 ==============================
Patient Name: Khizar

Patient Data(before):
0 in:  0 lbs: 

Patient Data(after):
height_inches: 65
weight_pounds:60
65 in:  60 lbs: 
In [13]:
class PatientData:
    def __init__(self):
        self.name = ""
        self.height_inches =0
        self.weight_pounds =0
        

print("========= information of patient_1 ==============================")        
patient = PatientData()  # object

Patient_Name = input("Patient Name: ")

print("\nPatient Data(before):")
print(patient.height_inches ,"in: ",end = " ")
print(patient.weight_pounds,"lbs: ")


print("\nPatient Data(after):")
patient.height_inches=input("height_inches: ")
patient.weight_pounds= input("weight_pounds:")

print(patient.height_inches ,"in: ",end = " ")
print(patient.weight_pounds,"lbs: ")




print("\n========= information of patient_2 ==============================") 

patient2 = PatientData()  # object

Patient_Name = input("Patient Name: ")

print("\nPatient Data(before):")
print(patient2.height_inches ,"in: ",end = " ")
print(patient2.weight_pounds,"lbs: ")


print("\nPatient Data(after):")
patient2.height_inches=input("height_inches: ")
patient2.weight_pounds= input("weight_pounds:")

print(patient2.height_inches ,"in: ",end = " ")
print(patient2.weight_pounds,"lbs: ")
========= information of patient_1 ==============================
Patient Name: Mike

Patient Data(before):
0 in:  0 lbs: 

Patient Data(after):
height_inches: 45
weight_pounds:35
45 in:  35 lbs: 

========= information of patient_2 ==============================
Patient Name: Zain

Patient Data(before):
0 in:  0 lbs: 

Patient Data(after):
height_inches: 55
weight_pounds:35
55 in:  35 lbs: 

task

the name of the class is Employee
    three attributes:
        name
        wage
        hours

1st method:
    def __init__(self,name,wage,hours)

2nd method:
    def calculate_pay(self)


 result:
    Zain: 
        Net pay: 165.0

   Khizar:
     NetPay : 165.0

   Hira:
    Net Pay:
        500.0
In [14]:
class Employee:
    def __init__(self,name,wage,hours):
        self.name = name 
        self.wage = wage
        self.hours = hours
        
    def calculate_pay(self):
        return self.wage*self.hours
    
zain = Employee("Zain",8.25,20)
zain.calculate_pay()
print("Zain:\n Net Pay:",zain.calculate_pay())


zain = Employee("Khizar",8.25,20)
zain.calculate_pay()
print("\nKhizar:\n Net Pay:",zain.calculate_pay())


zain = Employee("Hira",12.50,40)
zain.calculate_pay()
print("\nHira:\n Net Pay:",zain.calculate_pay())


Mike = Employee("Mike",14.50,40)
zain.calculate_pay()
print("\nMike:\n Net Pay:",zain.calculate_pay())
Zain:
 Net Pay: 165.0

Khizar:
 Net Pay: 165.0

Hira:
 Net Pay: 500.0

Mike:
 Net Pay: 500.0

task02

if age is less than 50 :
    Hello ,how are you doing
if age is greater than 50:
    Hello,how are you 

=============information of 1st person=================
Mike
15
Mike 15
I am a student and my name is Khizar and my age is  15
Hello,how are you doing

==============information of 2nd person===============================
Mariam
54
Mariam 54
I am a student and my name is Mariam and my age is  54
Hello,how are you.
In [15]:
class Person:
    def set_details(self,name,age):
        self.name = name
        self.age = age
        
        
    def information(self):
        print(self.name,self.age)
        
    def display(self): 
        print("I am a student and my name is",self.name,"and my age is ",self.age)
        
    def greet(self):
        if self.age <50:
            print("Hello,how are you doing")
        else:
            print("Hello,how are you")
        
p1 = Person()
p2= Person()

print("=============information of 1st person=================")
p1.set_details("Mike",15)
print(p1.name)
print(p1.age)
p1.information()
p1.display()
p1.greet()

print("\n==============information of 2nd person===============================")
p2.set_details("Mariam",54)
print(p2.name)
print(p2.age)
p2.information()
p2.display()
p2.greet()
=============information of 1st person=================
Mike
15
Mike 15
I am a student and my name is Mike and my age is  15
Hello,how are you doing

==============information of 2nd person===============================
Mariam
54
Mariam 54
I am a student and my name is Mariam and my age is  54
Hello,how are you
In [ ]:
fall21  09-14-21
In [ ]:
 
In [ ]:
 
In [ ]:
s21 03-22-21
In [1]:
class Movie:
    def __init__(self,title,director,writer):
        self.title = title
        self.director = director
        self.writer = writer
        
    def info(self):
        print("Movie Name: ",self.title)
        print("director name: ",self.director)
        print("Writer name: ",self.writer)
        
list_of_movies = []
while True:
    title = input("Enter Movie Name: ")
    director =input("Enter director name: ")
    writer = input("Enter Writer name: ")
    m = Movie(title,director,writer)
    list_of_movies.append(m)
    print("movies added successfully")
    option =input("\nDo you want to add one more movie [Yes|No]: ")
    if option== "No":
        break
Enter Movie Name: Soul
Enter director name: Docter
Enter Writer name: Jones
movies added successfully

Do you want to add one more movie [Yes|No]: Yes
Enter Movie Name: Matrix
Enter director name: Lana
Enter Writer name: Lilly
movies added successfully

Do you want to add one more movie [Yes|No]: No

No comments:

Post a Comment