Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
2.tutorial 2-if & else-
1. MIET MiET SCHOOL
of Engineering
Engineers are driving the future
Python Programming
Tutorial 2
Learn & Lead
Eng. Ruwan Dissanayake
B.Sc.Eng(Hons) Electrical & Electronic Engineer , AMIESL
Former Engineer Corporate Strategy Sri lanka Telecom PLC
Dip.in. Counselling Psychology, Dip.in. Stress Management
Dip.in Buddhist Counselling Psychology(SIBA),
Dip.in Interior Designing, Design in Electrical Installation(IESL)
Certified Motivation Personality & Leadership Trainer
Certified Energy Healing Therapist & Counselor
077 593 10 68 / 071 241 70 27
PRE -ENGINEERING COURSE 2021
2. Tutorial 2-Individual
Python programming- Flow Control-if ....else
1. Develop a program which accepts a number (an amount of money to be paid by a
customer in rupees) entered from the keyboard. If the amount is greater than or equal to
1,000 rupees, a 5% discount is given to the customer.Then display the final amount that
thecustomerhastopay.
2. Modify the program for the question 1 so that it displays the message “No discount…”
iftheamountislessthan1,000.
3. Write a program that reads the marks obtained for a given subject and display the given
message.
• 0-50=>“Fail”
• 51-100=>“Pass”
4. Write a python program to implement the Number Guessing Game. In this game the
computer chooses a number between 1 and 10, and the player tries to guess the number
in one attempt. Each time the player enters a guess, the computer tells him whether the
guess istoohighortoolow.
MIET MiET SCHOOL
of Engineering
Engineers are driving the future
5. writedown suitablecodingto find largestoftwogivennumbers
Guess My Number Game
Enter a guess between 1 and 10 : 2
Too low!
Guess no=4 Guess no=4
6. Write a Python program which accepts the radius of a circle from the user and compute
thearea.
Guess My Number Game
Enter a guess between 1 and 10 : 7
Too high!
Input: num1 = 10, num1 = 45
Output: Largest number = 45
Input: num1 = 20, num1 = 18
Output: Largest number = 20
3. MIET MiET SCHOOL
of Engineering
Engineers are driving the future
7. WriteaPythonprogramtogetthevolumeofasphere
8. Write a Python program to get the absolute difference between a given number and 17,
ifthenumberisgreaterthan17returndoubletheabsolutedifference.
9. Write a Python program to calculate the sum of three given numbers, if the values are
equalthenreturnthreetimesoftheirsum.
11. Write a Python program to find whether a given number (accept from the user) is even
orodd,printoutanappropriatemessagetotheuser.
Input: num = 10
Output: This is an even number
Input: num = 1211
Output: This is an odd number
12.Write a Python program that
will accept the base and
height of a triangle and
computethearea.
4. MIET MiET SCHOOL
of Engineering
Engineers are driving the future
13. Write a Python program to compute the future value(maturity Value) of a specified
principalamount,rateofinterest,andanumberofyears.
Input: Princi_Amount = 10000, interest = 3.5, years = 7
Output: Maturity Value : 12722.79
14. Write a Python program which will return true if the two given integer values are equal
ortheirsumordifferenceis5
Input: num1 = 7
num2 = 3
Output: false
Input: num1 = 7
num2 = 2
Output: true
15. Write a Python program to compute the distance between the points (x1, y1) and
(x2,y2).
16.WriteaPythonprogramtoconvertallunitsoftimeintoseconds.
Input:
Output:
days: 4
hours: 5
minutes: 20
seconds: 10
The amounts of seconds 364810
5. MIET MiET SCHOOL
of Engineering
Engineers are driving the future
17.WriteaPythonprogramtocalculatemidpointsofaline
Input:
Output:
Calculate the midpoint of a line :
The value of x (the first endpoint) 2
The value of y (the first endpoint) 2
The value of x (the first endpoint) 4
The value of y (the first endpoint) 4
The midpoint of line is :
The midpoint's x value is: 3.0
The midpoint's y value is: 3.0
18.WriteaPythonprogramtocalculatebodymassindex.
Input your height in meters: 1.2
Input your weight in Kilogram: 65
Your body mass index is: xxx
Output:
Input:
19.WriteaPythonprogramtoswap twovariables.
a : 20
b: 65
a=65 , b=20
Output:
Input:
20.WriteaPythonprogram toconverttemperaturefromFahrenheittoCelsius.
Temp.in Fahrenheit : 50
Temp.in Celsius : 10
Output:
Input:
6. MIET MiET SCHOOL
of Engineering
Engineers are driving the future
21.WriteaPythonprogramtoconvertdegreetoradian.
Input:
Output:
Degree : 15
radians: 0.2619047619047619
22.WriteaPythonprogramtoconvertradiantodegree..
Input:
Output:
Radian : 52
Degree: 29.781818181818185
23.WriteaPythonprogramtocalculate volumeandsurfaceareaofacylinder
Input:
Output:
Height : 4
Radius : 6
Volume is : 452.57142857142856
Surface Area is : 377.1428571428571
24.WriteaPythonprogramtofind therootsofaquadraticfunction.
Input:
Output:
Quadratic function : (a * x^2) + b*x + c
a: 5
b: 20
c: 10
There are 2 roots: -0.585786 and -3.414214
Input:
Input:
Output:
Output:
Quadratic function : (a * x^2) + b*x + c
a: 1
b: 4
c: 2
There is one root: 2
Quadratic function : (a * x^2) + b*x + c
a: 1
b: 2
c: 4
No roots
7. MIET MiET SCHOOL
of Engineering
Engineers are driving the future
25.WriteaPythonprogramtocheckthevalidityofa simplePassword
Input:
Output:
Enter password : hello123
incorrect password
password = hello456
Input:
Output:
Enter password : hello456
You are welcome
password = hello456
26.modifythe25thprogram thatasks theusertoinputausernameandpassword.
Input:
Output:
username : Eng
password : hello456
incorrect password
password = hello456 password = hello456
user_name = Pre_Engineering user_name = Pre_Engineering
Input:
Output:
username : Pre_Engineering
password : hello456
You are welcome
Special notes
Ÿ Send your code & screenshots of the output as a single pdf file and do not forget to save your
documentusing your registrationnumber.
Ÿ (your Reg.Nois 96 => )
96. ME_96_YourName
Ÿ Please submit your assignment to mietschoolofengineering@gmail.com