0% found this document useful (0 votes)
7 views14 pages

Subhan

This document outlines a lab exercise for a Computer Programming course focused on implementing branching programs in Python. It covers the objectives, theoretical explanations of if, if-else, nested if-else, and elif statements, as well as several tasks for students to complete using these concepts. The lab tasks include writing programs to determine enrollment year, find the largest number among three inputs, and check if a number is even, among others.

Uploaded by

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

Subhan

This document outlines a lab exercise for a Computer Programming course focused on implementing branching programs in Python. It covers the objectives, theoretical explanations of if, if-else, nested if-else, and elif statements, as well as several tasks for students to complete using these concepts. The lab tasks include writing programs to determine enrollment year, find the largest number among three inputs, and check if a number is even, among others.

Uploaded by

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

Course Name

Computer Programing
lab(1009)

Lab Title

Implement Branching Programs in


python (if, if- else, nested if else,
Elif)

Name Registration Number Lab #

Subhan afzal F 24604023 2nd

Instructor’s Name Instructor’s


Date
Signature

Lec Ayesha Ashfaque


2 March 2025
Lab #02:

Implement Branching Programs in python (if, if-else,nested if else,


elif)

Objective:

● To have basic understanding of if-else Statements in Python.

● To understand Nested if statements and else-if statements.

Tools/Software Requirement:
Python 3 Anaconda

Theoretical Explanation:
1. if Statement:

The if statement is used when you want to make a decision. It checks if a certain condition is true
or not. If the condition is true, the block of code inside the if statement gets executed.

2. if-else Statement:

An if-else statement is like a choice between two options. If the condition is true, the if part is
executed; if it’s false, the else part is executed.

3. Nested if-else:

A nested if-else is when you place an if-else statement inside another if or else statement. It’s
useful when you want to check multiple conditions step by step.

4.elif (else if):


elif stands for "else if." It allows you to check multiple conditions in a sequence. It’s like saying
"if this condition is true, do something; otherwise, if this other condition is true, do something
else." You can have multiple elif conditions.

Lab Tasks:

Task #1:

Your university registration number shows the year of your intake. For example, in the

enrolment 201918 the first two numbers show your intake i.e. 20. Write a python

program which takes enrolment as an input and finds in which year you are enrolled ?

Code :

print('subhan afzal:-:')

d=input('enter your full rollno:-:')

print('your of batch :-:',d[3:5])

Input:
Output:

Flow chart:

Start

Input num

Display num[3:5]

End

Task #2:

Write a python program to find the largest number among the three user input numbers.
Code:

1. print('subhan afzal :-:')


2. num1=int(input("enter first number :"))
3. num2=int(input("enter second number :"))
4. num3=int(input("enter third number :"))
5. if num1>num2 and num1>num3: print("number 1 is greater number ")
6. elif num2>num2 and num2>num3: print("number 2 is greater number ")
7. else: print("number 3 is greater number ")
Input:

Output:

Flow chart:

Start

Input a,b,c
Task #3:

Write a phyton code to check whether a number is even or not.

Code:

print (“Subhan Afzal: -: “')

number=int (input ("enter a number: -:"))

if number%3==0:
print('\nits an odd number')

else:

print('\nits an even number')

Input:

Output:

Flow chart:

Start
Post lab task: -
Task 1:
Input:

Output:

Flow-chart:- Start Input n

I =1

Range
Display
(1,n+
i
1)

End
Task #2:

Input:
Output:

Flow-chart

Input user_input For c in


Start
User input

end Print c

Task #3:
Input:
Output:

Flow-chart:
Start

Input n

Sum_even=0

For i
Range(1,n
+1)

End Even_number=2*i

Sum_even=sumn+even_numb
Task #4: er

Input:
Output:

Flow-chart:

Start
Input n

For I

Range(n)

End Space=” “*i

Stars=”*”*(2*(i)-1)
Task #5:
Input:
Output:

Flow-chart: Start

Input s

If
s==s[::-
1]

Its not a
plaindrome It’s a plaindrome

End

Task #6:
Input :
Output:

You might also like