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

Program 1: Lab Task #5

The document outlines 7 programming tasks involving while loops. The tasks include: 1) a simple while loop with a final condition, 2) an infinite while loop, 3) a loop that sums values within a limit, 4) a loop with an else condition, 5) a function that squares and adds one to a value, 6) an empty task, and 7) 3 questions involving while loops to generate odd numbers, a pyramid pattern, and another pyramid pattern. Programming exercises at the end involve writing while loops to generate outputs matching the patterns.

Uploaded by

ayaan khan
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)
35 views

Program 1: Lab Task #5

The document outlines 7 programming tasks involving while loops. The tasks include: 1) a simple while loop with a final condition, 2) an infinite while loop, 3) a loop that sums values within a limit, 4) a loop with an else condition, 5) a function that squares and adds one to a value, 6) an empty task, and 7) 3 questions involving while loops to generate odd numbers, a pyramid pattern, and another pyramid pattern. Programming exercises at the end involve writing while loops to generate outputs matching the patterns.

Uploaded by

ayaan khan
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

LAB TASK #5

Program 1
Practicing with simple while loop, giving them the final condition of loop.

INPUT:

OUTPUT:
Program 2

Practicing with simple while loop with infinite iterations as the condition is always
true.

INPUT:

OUTPUT:
Program 3
Write a program which takes the limit for while loop condition and sum the total
amount

INPUT:

OUTPUT:
Program 4
Practicing with simple while loop with else condition.

INPUT:

OUTPUT:
Program 5
Write a function f which takes one argument x, it will square the value of x
and add 1 in it then return the answer to user.

INPUT:

OUTPUT:
Program 6

INPUT:

OUTPUT:
Program 7
INPUT:

OUTPUT:
PROGRAMMING EXERCISES:

Q1 Write down a Python program, using While loop that generates Odd no’s in
between 1 to 100.

INPUT:

OUTPUT:
Q.2 Write down a Python Program using While loop to generate the following output.
1. **************
**************
**************
**************
**************
**************
**************
**************
INPUT:

OUTPUT:
2. *
**
***
****
*****
******
*******
********

INPUT:

OUTPUT:
3. ********
*******
*****
****
***
**
*

INPUT:

OUTPUT:
Q.3 Write down a python program having one function for calculating factorial of a no.

And call that function within a While loop to generate factorial of numbers from 0 to 10

INPUT:

OUTPUT:

You might also like