0% found this document useful (0 votes)
22 views7 pages

Compress Lab 4 (1) 20230609131037

The document contains a student's laboratory report on logic operations and decision making in Python. It includes 4 questions asking the student to write Python programs that: 1) check if a number is positive, negative, or zero; 2) check if a year is a leap year; 3) display the roots of a quadratic equation; and 4) perform arithmetic operations based on user input. For each question, the student documents the algorithm, program, sample output, and conclusion drawn about using conditional statements to control program flow.

Uploaded by

Slayer Shank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Compress Lab 4 (1) 20230609131037

The document contains a student's laboratory report on logic operations and decision making in Python. It includes 4 questions asking the student to write Python programs that: 1) check if a number is positive, negative, or zero; 2) check if a year is a leap year; 3) display the roots of a quadratic equation; and 4) perform arithmetic operations based on user input. For each question, the student documents the algorithm, program, sample output, and conclusion drawn about using conditional statements to control program flow.

Uploaded by

Slayer Shank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

NAME=SHASHANK M Registration Number:22ETRE409026

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.

2. Aim and Objectives


Aim
• To develop programs involving branching using appropriate control statements in
Python
Objectives
At the end of this lab, the student will be able to
• Apply conditional control statements such as if-else and nested if-else to express
decisions
3. Experimental Procedure
i. Analyse the problem statement
ii. Design an algorithm for the given problem statement and develop a
flowchart/pseudo-code
iii. Implement the algorithm in Python language
iv. Execute the Python program
v. Test the implemented program
vi. Document the Results
vii. Analyse and discuss the outcomes of the experiment
4. Questions
a. Write a Python program to check whether the given number is zero, positive or
negative

❖ 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:

Using if else condition we have validated the number whether its


positive or negative or zero
b. Write a Python program to check whether the given year is leap year or not.

❖ 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:

Using If else condition we have checked whether a year is leap


year or not
c. Write a Python program to display the roots of a quadratic equation.

• 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:

Using If elif conditions we have determined the roots of the


quadratic function

d. Write a Python program to perform arithmetic operations.


(provide option to the user for entering numbers and his/her choice )

• 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy