Day - 9 at payilagam "Looping"

What is loop Loops or Iteration Statements in Programming are helpful when we need a specific task in repetition. They're essential as they reduce hours of work to seconds. In this article, we will explore the basics of loops, with the different types and best practices While loop : Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied. When the condition becomes false, the line immediately after the loop in the program is executed. no1 = int(input("enter no :")) no2 = int(input("enter no :")) if no1>no2: print(no1) elif no1

Apr 10, 2025 - 12:35
 0
Day - 9 at payilagam "Looping"

What is loop

Loops or Iteration Statements in Programming are helpful when we need a specific task in repetition. They're essential as they reduce hours of work to seconds. In this article, we will explore the basics of loops, with the different types and best practices

While loop :
Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied. When the condition becomes false, the line immediately after the loop in the program is executed.

no1 = int(input("enter no :"))
no2 = int(input("enter no :"))

if no1>no2:
   print(no1)

elif no1

instead:

no = 1
while no<=5
     print(no,end=' ')
     no+=1

Variable length argument.
print statement take many arguments as possible.


print("hi")
print("hi","hello")
print("mohammed","salman")
print(5,10,15)
print('09','April','2025',sep = '-',end='/')
print('09','April','2025',end='#')

Use python visualizer to visualize

*Addition of first N nnumbers : *

no = 1
total = 0
while no<=5:
    print(no,end=' ')
    total = total+no
    no+=1
print('\n',total,sep=' ')

Multiplication of First N numbers

no = 1
total = 5
while no < 5:
      print(no,end=' ')
      total = total * no
      no+=1
print('\n', total,sep=' ')
no = 1
while no<=10:
      if no%6 ==0:
         break
      print(no)
      no+=1

no = 1
while no<=5:
     if no%4 == 0:
        break
     print(no)
     no+=1
else :
    print("hi",no)

PS1 = "[OPMB10 $]" PS1 is an environment variable in Linux that defines the primary command prompt's appearance in the terminal. It allows users to customize their prompt to include information like the username, hostname, current directory, and even colors, enhancing the terminal experience.

TASK:
1) odd or even

no1 = 1
no2 = 10

while no1 <= no2:
    if start % 2 == 0:
        print("It is Even")
    else:
        print("It is Odd")
    no1 += 1

2)prime number

num = int(input("Enter a number: "))
i = 2

if num <= 1:
    print("Not Prime")
else:
    while i < num:
        if num % i == 0:
            print("Not Prime")
            break
        i += 1
    else:
        print("Prime")