0% found this document useful (0 votes)
2 views3 pages

Python Exp 03

This document outlines a Python Programming Lab course for BCA students, focusing on branching statements. It includes theoretical explanations, algorithms, and sample programs demonstrating the use of if, if-else, and if-elif-else statements to control program flow. The document provides practical examples for determining the sign of a number, finding the greatest of three numbers, performing arithmetic operations, and assigning grades based on marks.

Uploaded by

tiwari06ap
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)
2 views3 pages

Python Exp 03

This document outlines a Python Programming Lab course for BCA students, focusing on branching statements. It includes theoretical explanations, algorithms, and sample programs demonstrating the use of if, if-else, and if-elif-else statements to control program flow. The document provides practical examples for determining the sign of a number, finding the greatest of three numbers, performing arithmetic operations, and assigning grades based on marks.

Uploaded by

tiwari06ap
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

Course: BCA Year/Semester: 2/IV

Subject code: BCA 412


Session: 2025-26
Subject Name: Python Programming Lab
Name of the faculty: Dr. Peeyush Kumar Pathak

EXPERIMENT 03

Program to demonstrate branching statement.

Theory:

Branching statements are used to control the flow of a program by making decisions based
on conditions.
They help a program choose different paths of execution.

Python supports the following branching statements:

 if statement
 if-else statement
 if-elif-else statement

Python uses indentation to define blocks of code.

Algorithm:

1. Start
2. Accept a number from user
3. Check if number is positive, zero or negative
4. Display result
5. Stop
PROGRAM: -1

num = int(input("Enter a number: "))


if num > 0:
print("Number is Positive")
elif num == 0:
print("Number is Zero")
else:
print("Number is Negative")

PROGRAM-2: greatest of among three Numbers and Arithmetic operator

# Program to find the greatest among three numbers


# Input three numbers

a = float(input("Enter first number: "))


b = float(input("Enter second number: "))
c = float(input("Enter third number: "))

# Compare the numbers


if a >= b and a >= c:
greatest = a
elif b >= a and b >= c:
greatest = b
else:
greatest = c

# Output the result


print("The greatest number is:", greatest)

# Arithmetic operator
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
op = input("Enter operator (+, -, *, /): ")

if op == '+':
print("Result =", a + b)
elif op == '-':
print("Result =", a - b)
elif op == '*':
print("Result =", a * b)
elif op == '/':
print("Result =", a / b)
else:
print("Invalid Operator")
PROGRAM 3: Grade System

marks = int(input("Enter marks: "))

if marks >= 80:


print("Grade A")
elif marks >= 60:
print("Grade B")
elif marks >= 40:
print("Grade C")
else:
print("Fail")

You might also like