0% found this document useful (0 votes)
7 views

Ex 3

Uploaded by

Sanjai
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 views

Ex 3

Uploaded by

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

NAME: C.

PALANIRAJ
Roll no: 24ITB46

SCIENTIFIC PROBLEMS USING CONDITIONALS AND ITERATIVE


Ex. No 3. LOOPS

Aim
The aim of this exercise is to write python script for the given program using conditionals
statements & iterative loops and execute the same in Python IDLE (through Script or Development
Mode).
Problems Given
1. Number Series
2. Number Patterns
3. Pyramid Patterns

Concepts Involved
Decision Making Statements:
● Decision making constructs begins with a Boolean expression, an expression that returns
either True or False.
● In Python programming, zero or null vales are assumed as false.
● Decision making structures are necessary to perform an action or a calculation only when a
certain condition is met.
● In Python we have the following types of decision making statements. They are:
o if statement
o if..else statements
o elif statements
o Nested if..elif..else statements
o Inline if
● Conditional if statement
Syntax:
if Boolean expression:
Statement 1
Statement 2

Statement n
● Alternative if…else statement
Syntax:
if test expression:
statements
else:
statements
● Chained Conditional if..elif…else statements
Syntax:
if test_expression:
statements
elif test_expression:
statements
…..
else:
NAME: C.PALANIRAJ
Roll no: 24ITB46

statements
● Nested if…elif…else statements
Syntax:
if test_expression:
if test_expressioon_a:
statements
elif test_expression_b:
statements
else:
statements
elif test_expression:
statements
else:
statements
● Inline if statements
Syntax:
do Task A if condition is true else do Task B

Iteration (or) Loops


● Generally statements are executed sequentially. The first statement is executed first and the
second statement is executed next and so on.
● There will be situations when we need to execute the block of code, a several number of
times.
● Python provides various control structures that allows for repeated execution.
● “A loop is a programming control structure that facilitates the repetitive execution of a
statement or group of statements”.
● Python provides two types of looping constructs.
● They are,
o For loop
o While loop
● For loop: It executes a sequence of statements that allows a code to be repeated a certain
number of times using the “range” and “xrange” function.
● While loop: It repeats a statement or group of statements as long as a certain Boolean
condition is met. It tests the condition before executing the loop body.

Syntax: for loop


for <variable> in <sequence>:
<statement 1>
…….
<statement n>
where, variable-stores all value of each item.
sequence-may be a string, collection or a range() which implies the loop’s
number.

Syntax: while loop


while Boolean expression:
statement 1
….
NAME: C.PALANIRAJ
Roll no: 24ITB46

statement n

1. Number Series

Code:

Output 1:

Output 2:
NAME: C.PALANIRAJ
Roll no: 24ITB46

2. Number Patterns

Code:

Output 1:

Output 2:
NAME: C.PALANIRAJ
Roll no: 24ITB46

3. Pyramid Patterns
Code:

Output 1:

Output 2:
NAME: C.PALANIRAJ
Roll no: 24ITB46

Rubrics Marks

Document Presentation

Timely submission

Total

Result:
NAME: C.PALANIRAJ
Roll no: 24ITB46

Thus , the given problems were implemented by python programming using conditional and
iteration loops and the output was verified successfully.

You might also like