0% found this document useful (0 votes)
36 views12 pages

Usman

The document outlines a lab titled 'Implement Branching Programs in Python' aimed at teaching students about if-else statements, nested if statements, and elif in Python. It includes objectives, theoretical explanations, and several coding tasks to practice these concepts. The conclusion reflects on the learning experience and understanding of programming logic through Python.

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)
36 views12 pages

Usman

The document outlines a lab titled 'Implement Branching Programs in Python' aimed at teaching students about if-else statements, nested if statements, and elif in Python. It includes objectives, theoretical explanations, and several coding tasks to practice these concepts. The conclusion reflects on the learning experience and understanding of programming logic through Python.

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/ 12

Course Name

Computer Programing
lab(1009)

Lab Title

Implement Branching Programs in


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

Name Registration Number Lab #

M Usman F 24604025 2nd

Instructor’s Name Instructor’s


Date
Signature

Lec Ayesha Ashfaque


3 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('M usman ')

rollno=input('enter your full rollno with f and a dash(-):-:')

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

Input:

phyton code to print batch info 1


Output:

Task #2:

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

Code:

1. print(' M Usman')
2. n1=int(input("enter first number :"))
3. n2=int(input("enter second number :"))
4. n3=int(input("enter third number :"))
5. if n1>n2 and n1>n3: print("number 1 is greater number ")
6. else: print("number 3 is greater number ")
Input:
phyton code to find the biggest number 1

Output:
Task #3:

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

Code:

print (“M Usman “')

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

if number%3==0:

print('\nits an odd number')

else:

print('\nits an even number')

Input:
phyton code to find the even and odd num 1

Output:

Task#4:

Code:

1. print("M usman")
2. int1=int(input("enter a number"))
3. if int1>1
4. for i in range(2,(int1//2)+1):
5. if int1%i==0:
6. print("its a prime number")
7. break
8. else:
9. print('its a prime number')
10. break
11. else:
12. print('its not a brime number')

Input:
phyton code to find prime number 1

Output:

Post lab task: -


Task 1:

Input:
Output:

Task #2:

Input:

Output:
Task #3:
Input:

Output:

Task #4:

Input:
Output:

Task #5:
Input:

Output:
Task #6:
Input :

Output:

:Conclusion:
In this lab we learned about if-else statements and also about
nested statements . it gave us idea about the would a phyton
code would perform under certain conditions and certain
scenarios more over its engage me epically in phyton programing
and let me understood many problem solving strategies.

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