SlideShare a Scribd company logo
1 of 14
Download to read offline
1
Introduction to Programming
with Python
Sudharshan Welihinda(weli@iit.ac.lk)
Senior Lecturer, Department of Computing
Informatics Institute of Technology
Lecture 04
Exercise
2
Problem 1 : Write an algorithm to read two numbers and find their sum.
Inputs : First number num1, Second number num2.
Process : Sum = num 1 + num2
Output: Sum (sum of the two numbers.)
Algorithm:
Step1: Start
Step2: Readinput the first num1.
Step3: Readinput the second num2.
Step4: Sum = num1+num2
Step5: Write/Output Sum
Step6: End
Python program
input(‘Enter first number’)
Num2 = int(input(‘Enter second number’))
Sum = Num1 + Num2
print(Sum)
Num1 = int( )
Exercise
3
Problem 2 : Calculate area of a rectangle.
Inputs : Width & Height
Process : Area = Width * Height
Output: Area.
Problem 3 : Find the average of three numbers input by user.
Inputs : Number1 , Number2, Number3
Process : Average = (Number1 + Number2 + Nmber3) / 3
Output: Average
Exercise
4
Problem 2.1 : Write a Python program to enter length and breadth of a rectangle and
find its perimeter.
Inputs : Length & Breadth
Process : Perimeter = (Length + Breadth) * 2
Output: Perimeter.
Problem 2.2 : Write a Python program to enter two angles of a triangle and find the
third angle.
Inputs : Angle1 & Angle2
Process : ThirdAngle = 180 – (Angle1 + Angle2)
Output: ThirdAngle
Exercise
5
Problem 4 : Write a python program to convert temperature Fahrenheit to Celsius
Inputs : Temperature in Fahrenheit
Process : C = 5/9 * (F-32)
Output: Temperature in Celsius .
Problem 5 : Write a python program to Determine the total cost of apples, given the
number of kilos of apples purchased and the cost of apples per kilo.
Inputs : Number of kilos of apples
Cost of apples per kilo
Process : Total cost = Number of kilos of apples * Cost of apples per kilo
Output: Total cost of apples
Exercise
6
Problem 6 :
Write a python program to calculate Body Mass Index(BMI). Body mass index calculator
is based on the standard BMI measurement that takes your weight and height and
basically tells you if you have an unhealthy body weight or not.
The official formula, which is used in this BMI calculator, is
BMI = (weight (Kg) / (height (m) x height (m))
Inputs : Weight, Height
Process : BMI = Weight / (Height x Height)
Output: BMI (Body Mass Index)
Exercise
7
Problem 6.1 :
Write a python program to enter marks of three subjects and calculate total, average and
percentage.
Answer
8
Problem 6 – Answer(without formatting):
Weight = 0.0
Height = 0.0
BMI = 0.0
Weight = float(input('Enter your body weight... '))
Height = float(input('Enter your Height... '))
BMI = (Weight/(Height * Height))
print('Your BMI index is = ‘, BMI)
Problem 6 – Answer(with print formatting):
Weight = 0.0
Height = 0.0
BMI = 0.0
Weight = float(input('Enter your body weight... '))
Height = float(input('Enter your Height... '))
BMI = (Weight/(Height * Height))
print('Your BMI index is = ',format(BMI,'.2f'))
9
Problem 7 :
Write a Python program to read sum of money, Increase it by 8% and print the original
and the increased sum.
Exercise
Problem 8 :
Write a Python program which accepts the radius of a circle from the user and
compute the area.
Assume π = 3.14
Problem 9 :
Write a Python program which accepts the user's first and last name and print them in
reverse order with a space between them
10
Problem 7 :
OriginalSum = 0.0
IncreasedSum = 0.0
Incremental = 0.0
OriginalSum = float(input('Enter original sum... '))
Incremental = (OriginalSum* 0.08)
IncreasedSum = OriginalSum + Incremental
print('Original Sum = ',format(OriginalSum,'.2f'))
print('Increased Sum = ',format(IncreasedSum,'.2f'))
Answer
11
Answer
Problem 8 :
Radius = 0.0
Area = 0.0
Radius = float(input('Enter radius of a circle... '))
Area = Radius * Radius * 3.14
print('Are is = ',format(Area,'.2f'))
12
Answer
Problem 9 :
FirstName = 0.0
LastName = 0.0
FirstName = input('Enter first name : ')
LastName = input('Enter last name : ')
print('Full Name is - ', FirstName, ‘ ', LastName)
# print('Full Name is - ', FirstName, end=‘’)
# print(' ' , LastName)
13
Problem 10 :
Programme is to be written to input the basic salary of an employee and to calculate
and display the net salary. Net salary is to be calculated by deducting 8.5% of EPF
contribution & 1% of society contribution from the basic salary.
a) Define the memory variables needed to hold the data items in this program.
b) Write the statement that will assign the input basic salary to respective memory
variable.
c) Write the statement that will calculate the net salary.
d) Write the statement that will display the net salary.
Exercise
14
Problem 11 :
Write a Python Program to convert days into years, weeks & days.
Exercise

More Related Content

Similar to DOC333-2023-Sep-pythonprogramming-Lec04.pdf

python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfrajatxyz
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfayush616992
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variablesIntro C# Book
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2Mohamed Ahmed
 
C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1Zaibi Gondal
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchartfika sweety
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answersQuratulain Naqvi
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)ExcellenceAcadmy
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)ExcellenceAcadmy
 
Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)iloveallahsomuch
 
Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)iloveallahsomuch
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18HIMANSHU .
 
Workshop03.docx lap trinh C cho người mới bắt đầu
Workshop03.docx  lap trinh C cho người mới bắt đầuWorkshop03.docx  lap trinh C cho người mới bắt đầu
Workshop03.docx lap trinh C cho người mới bắt đầulinhtran111111111111
 

Similar to DOC333-2023-Sep-pythonprogramming-Lec04.pdf (20)

lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
python.pdf
python.pdfpython.pdf
python.pdf
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdf
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variables
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
 
C programming Lab 1
C programming Lab 1C programming Lab 1
C programming Lab 1
 
xii cs practicals
xii cs practicalsxii cs practicals
xii cs practicals
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchart
 
Python Manuel-R2021.pdf
Python Manuel-R2021.pdfPython Manuel-R2021.pdf
Python Manuel-R2021.pdf
 
PROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docxPROGRAMMING QUESTIONS.docx
PROGRAMMING QUESTIONS.docx
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
 
Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)
 
Python summer course play with python (lab1)
Python summer course  play with python  (lab1)Python summer course  play with python  (lab1)
Python summer course play with python (lab1)
 
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORYGE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
 
algorithm
algorithmalgorithm
algorithm
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
 
Workshop03.docx lap trinh C cho người mới bắt đầu
Workshop03.docx  lap trinh C cho người mới bắt đầuWorkshop03.docx  lap trinh C cho người mới bắt đầu
Workshop03.docx lap trinh C cho người mới bắt đầu
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 

DOC333-2023-Sep-pythonprogramming-Lec04.pdf

  • 1. 1 Introduction to Programming with Python Sudharshan Welihinda(weli@iit.ac.lk) Senior Lecturer, Department of Computing Informatics Institute of Technology Lecture 04
  • 2. Exercise 2 Problem 1 : Write an algorithm to read two numbers and find their sum. Inputs : First number num1, Second number num2. Process : Sum = num 1 + num2 Output: Sum (sum of the two numbers.) Algorithm: Step1: Start Step2: Readinput the first num1. Step3: Readinput the second num2. Step4: Sum = num1+num2 Step5: Write/Output Sum Step6: End Python program input(‘Enter first number’) Num2 = int(input(‘Enter second number’)) Sum = Num1 + Num2 print(Sum) Num1 = int( )
  • 3. Exercise 3 Problem 2 : Calculate area of a rectangle. Inputs : Width & Height Process : Area = Width * Height Output: Area. Problem 3 : Find the average of three numbers input by user. Inputs : Number1 , Number2, Number3 Process : Average = (Number1 + Number2 + Nmber3) / 3 Output: Average
  • 4. Exercise 4 Problem 2.1 : Write a Python program to enter length and breadth of a rectangle and find its perimeter. Inputs : Length & Breadth Process : Perimeter = (Length + Breadth) * 2 Output: Perimeter. Problem 2.2 : Write a Python program to enter two angles of a triangle and find the third angle. Inputs : Angle1 & Angle2 Process : ThirdAngle = 180 – (Angle1 + Angle2) Output: ThirdAngle
  • 5. Exercise 5 Problem 4 : Write a python program to convert temperature Fahrenheit to Celsius Inputs : Temperature in Fahrenheit Process : C = 5/9 * (F-32) Output: Temperature in Celsius . Problem 5 : Write a python program to Determine the total cost of apples, given the number of kilos of apples purchased and the cost of apples per kilo. Inputs : Number of kilos of apples Cost of apples per kilo Process : Total cost = Number of kilos of apples * Cost of apples per kilo Output: Total cost of apples
  • 6. Exercise 6 Problem 6 : Write a python program to calculate Body Mass Index(BMI). Body mass index calculator is based on the standard BMI measurement that takes your weight and height and basically tells you if you have an unhealthy body weight or not. The official formula, which is used in this BMI calculator, is BMI = (weight (Kg) / (height (m) x height (m)) Inputs : Weight, Height Process : BMI = Weight / (Height x Height) Output: BMI (Body Mass Index)
  • 7. Exercise 7 Problem 6.1 : Write a python program to enter marks of three subjects and calculate total, average and percentage.
  • 8. Answer 8 Problem 6 – Answer(without formatting): Weight = 0.0 Height = 0.0 BMI = 0.0 Weight = float(input('Enter your body weight... ')) Height = float(input('Enter your Height... ')) BMI = (Weight/(Height * Height)) print('Your BMI index is = ‘, BMI) Problem 6 – Answer(with print formatting): Weight = 0.0 Height = 0.0 BMI = 0.0 Weight = float(input('Enter your body weight... ')) Height = float(input('Enter your Height... ')) BMI = (Weight/(Height * Height)) print('Your BMI index is = ',format(BMI,'.2f'))
  • 9. 9 Problem 7 : Write a Python program to read sum of money, Increase it by 8% and print the original and the increased sum. Exercise Problem 8 : Write a Python program which accepts the radius of a circle from the user and compute the area. Assume π = 3.14 Problem 9 : Write a Python program which accepts the user's first and last name and print them in reverse order with a space between them
  • 10. 10 Problem 7 : OriginalSum = 0.0 IncreasedSum = 0.0 Incremental = 0.0 OriginalSum = float(input('Enter original sum... ')) Incremental = (OriginalSum* 0.08) IncreasedSum = OriginalSum + Incremental print('Original Sum = ',format(OriginalSum,'.2f')) print('Increased Sum = ',format(IncreasedSum,'.2f')) Answer
  • 11. 11 Answer Problem 8 : Radius = 0.0 Area = 0.0 Radius = float(input('Enter radius of a circle... ')) Area = Radius * Radius * 3.14 print('Are is = ',format(Area,'.2f'))
  • 12. 12 Answer Problem 9 : FirstName = 0.0 LastName = 0.0 FirstName = input('Enter first name : ') LastName = input('Enter last name : ') print('Full Name is - ', FirstName, ‘ ', LastName) # print('Full Name is - ', FirstName, end=‘’) # print(' ' , LastName)
  • 13. 13 Problem 10 : Programme is to be written to input the basic salary of an employee and to calculate and display the net salary. Net salary is to be calculated by deducting 8.5% of EPF contribution & 1% of society contribution from the basic salary. a) Define the memory variables needed to hold the data items in this program. b) Write the statement that will assign the input basic salary to respective memory variable. c) Write the statement that will calculate the net salary. d) Write the statement that will display the net salary. Exercise
  • 14. 14 Problem 11 : Write a Python Program to convert days into years, weeks & days. Exercise