Compress Lab 4 (1) 20230609131037
Compress Lab 4 (1) 20230609131037
Laboratory 4
Title of the Laboratory Exercise: Logic operations and decision making
1. Introduction and Purpose of Experiment
Python provides number of control flow instructions/statements to control the flow of
program execution conditionally. By solving the problems, students will be able to apply
conditional control statements to control the program execution.
❖ Algorithm:
Step 1: Start
Step 2: Take input from user and assign it variable n
Step 3: If variable n is less than zero, print n is a negative number
Step 4: If variable n is more than zero, print n is positive number
Step 5: If the variable n is equal to 0, print n is zero
Step 6: Stop
❖ Program:
❖ Presentation of result:
❖ Conclusion:
❖ Algorithm:
Step 1: Start
Step 2: Take input from user and assign it to y
Step 3: Check if y is either a multiple of 4 or 400 but not of 100. If
condition is satisfied output y is a leap year, else output y
output is not leap year
Step 4: Stop
• Flowchart:
Start
Input y
Yes
If y%4==0 and
Print y is
y%400==0 or leap year
y%100!=0
No
Print y is not
leap year
Stop
• Program:
• Presentation of result:
• Conclusion:
• Algorithm:
Step 1: Start
Step 2: Take input from user and assign it to variable a,b,c
Step 3: Find the determinant by using formula b**2-4a*c assign it
To d
Step 4: If d is less than zero, then output roots are imaginary
Step 5: If d is equal to zero, then output value of -b/(2*a)
Step 6: If d is greater than zero output values (-b+d**0.5)/(2*a) and
(-b-d**0.5)/(2*a)
Step 7: Stop
• Program:
• Presentation of result:
• Conclusion:
• Algorithm:
Step 1: Start
Step 2: Take input of two number and assign the values to n1 and
n2
Step 3: Take input of choice and assign it to o
Step 4: If the value of o is 1, 2, 3 or 4 execute the operation as
addition, subtraction, multiplication or division of a and b
respectively and output the value
Step 5: Stop
• Program:
• Presentation of result:
• Conclusion:
We have now allowed user to opt his own mathematical operation
using if else condition