0% found this document useful (0 votes)
13 views6 pages

Data Sci Lab 3

This document discusses conditional statements in Python. It outlines the objectives of learning about conditional statements like if, elif, and else. It explains the syntax and usage of these statements, how they allow the program flow to change based on conditions. Examples are given to check for even/odd numbers, divisibility by 5, and primality of a number. The tasks demonstrate how conditional statements make code more flexible and responsive to different situations.

Uploaded by

20jzind0168
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)
13 views6 pages

Data Sci Lab 3

This document discusses conditional statements in Python. It outlines the objectives of learning about conditional statements like if, elif, and else. It explains the syntax and usage of these statements, how they allow the program flow to change based on conditions. Examples are given to check for even/odd numbers, divisibility by 5, and primality of a number. The tasks demonstrate how conditional statements make code more flexible and responsive to different situations.

Uploaded by

20jzind0168
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/ 6

IE- DATA SCIENCE

Lab No: 03

Submitted to: Dr. Irfaan Ahmed


Submitted By: Muhammad Sharjeel khan
Muhammad Ahmad
Mudassir Hussain
Registration No: 20JZIND0168
20JZIND0162, 20JZIND0161
Department: Industrial Engineering
Semester: 7th/Fall 2023
Marks:
GPA MARKS

OBE MARKS

LAB REPORT RUBRIC 1

LAB REPORT RUBRIC 2

University of Engineering & Technology, Peshawar


Jalozai Campus
Lab #03:

“To perform the uses of conditional statements in Python”


Objectives:
 To know the concept of conditional statements in Python, outlining their importance in
programming.
 To explain the basic syntax and usage of the "if" statement in Python, including the role of
indentation and code blocks in its execution.
 To explore the "elif" statement and its significance in handling multiple conditions, enabling
readers to create more complex decision structures in their code.

Introduction:
Python is a versatile and widely-used programming language that allows developers to perform various
tasks, from simple calculations to complex data manipulation. One of the fundamental features that
enable this versatility is the use of conditional statements. In this article, we will explore how to harness
the power of conditional statements in Python, helping you make your code more flexible and responsive.

Conditional Statements in Python:


Conditional statements are essential for controlling the flow of a program. They allow us to make
decisions within our code, executing specific blocks of instructions when certain conditions are met. The
basic conditional statements in Python are "if," "elif," and "else."
Python relies on indentation to define code blocks. The indented code beneath the "if" statement will
execute only if the condition is true. This distinctive feature of Python enforces code readability and
structure. Using "elif" for Multiple Conditions
When you have multiple conditions to check, you can use "elif," short for "else if." This statement allows
you to handle multiple cases, and it will be executed if the preceding "if" or "elif" conditions are false.

The "else" Statement:


The "else" statement comes in handy when you want to provide an alternative action to take if none of the
previous conditions are met.

Procedure:
 Open the python compiler of your own choice.
 Then write a script for the first task.

Task 1: (check for even or odd number)


num = int(input("x"))
if num % 2 == 0:
print("num is even.")
else:
print("num is odd.")
Fig #3.1(even or odd check)

Fig #3.2(Console window)

Task 2: (check for divisible)


num = int(input("x"))
if num % 5 == 0:
print("num is divisible by 5.")
else:
print("num is not divisible by 5.")
Fig #3.3(check if the number is divisible by 5)

Fig #3.4(console window)

Task 3: (prime number check)


def is_prime(num):
if num <= 1:
return False
elif num <= 3:
return True
elif num % 2 == 0 or num % 3 == 0:
return False
num = int(input("X"))
if is_prime(num):
print("num is a prime number.")
else:
print("num is not a prime number.")

Fig #3.5(prime number check)

Fig #3.6(console window)


Results and discussion:
In this article, we have explored the diverse applications and utility of conditional statements in Python.
We will now discuss the key takeaways and the significance of understanding and effectively using these
fundamental programming constructs. By explaining the syntax and functionality of "if," "elif," and "else"
statements provide the basic building blocks for these decisions we provided readers with the essential
tools to create straightforward conditional structures in their Python programs.

Conclusion:
In conclusion, conditional statements are a powerful tool in Python that allows you to add decision-
making capabilities to your code. By using "if," "elif," and "else" statements, you can create dynamic and
responsive applications that react to different situations. Different examples/ tasks were performed for the
else and elif statements and the programs were written for these tasks.

You might also like