In computer programming world, loop represents a sequence of instructions that is continually repeated until a certain condition is reached or the number of times we wanted to executed is completed. A loop is a fundamental programming idea that is commonly used in writing programs. Python programming achieves loop using for and while. For executes the specific number of times the set of intructions where as while repeats until the condition breaks or becomes false. Lets see them with examples.
WHILE Statement
FOR Statement
Programs to demonstrate the working of these loops:
#WAP to print multiples of 3 until you reach 200 print("Second For Loop") |
#Programs to generate different patterns |
#Assignment 2: Print equilateral triangle pattern print(" ",end="") print("Pattern 3")
|
Assignments
1. # Assignment 1: Modify the Total Avg marks calculation program to do it for 5 students
# Assignment 2: Modify your Voting program (eligible to vote or not) to a repeat it for multiple input until
# user wants to continue
- Write a Python program that computes the factorial of an integer.
- Program to find sum N natural numbers
- Write code to display and count the factors of a number
- Program to check if eligible to vote in India
- Enter marks of 3 subjects for 5 students and grade them. Check for data validity and use BREAK and CONTINUE where necessary
- Check the type of a Triangle: Isosceles, Equilateral, Scalene, Right Angle
- Input 3 numbers and re-arrange them in ascending order. Use BOOLEAN