0% found this document useful (0 votes)
2 views3 pages

Loops Class Python

The document contains various examples of Python code demonstrating the use of loops, specifically while loops, for different tasks such as summing numbers, printing patterns, and reading inputs. Each code snippet illustrates a specific functionality, including calculating averages, products, and displaying characters of a string. The examples serve as practical applications of loop constructs in programming.

Uploaded by

kvenu8637
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Loops Class Python

The document contains various examples of Python code demonstrating the use of loops, specifically while loops, for different tasks such as summing numbers, printing patterns, and reading inputs. Each code snippet illustrates a specific functionality, including calculating averages, products, and displaying characters of a string. The examples serve as practical applications of loop constructs in programming.

Uploaded by

kvenu8637
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Loops:

code:
a=int(input())
counter=0 >> is Initialization condition
while CONDITION: >>is required to repeat the block of code
a=a+1
print(a) >>to print(a)
counter= counter+1 >> Updation
print("End")

a=int(input())
counter=0
while counter<3:
a=a+1
print(a)
counter=counter+1
print("End")

a=int(input())
counter=0
while counter<a:
row=a*"* "
print(row)
counter=counter+1

m=int(input())
n=int(input())
while m<=n:
print(m)
m=m+1

n=int(input())
counter=1
while counter<=n:
print(counter)
counter=counter+1

n=int(input())
counter=0
sum=0
while counter<n:
counter=counter+1
sum=sum+counter
avg=(sum/n)
print(avg)

rows=int(input())
columns=int(input())
counter=0
while counter<rows:
print( columns * "* ")
counter=counter+1

write a program that reads two numbers m and n and prints the sum of n numbers
from m-------------------------

m=int(input())
n=int(input())
counter=0
sum=0
while counter<n:
num=counter+m
sum=sum+num
counter=counter+1
print(sum)

solid right angled triangle------------------

a=int(input())
counter=1
while counter<=a:
print(counter*"* ")
counter=counter+1

sum of N natural numbers-----------------------

n=int(input())
counter=0
sum=0
while counter<n:
counter=counter+1
sum=sum+counter
print(sum)

read N inputs-----------------------------

n=int(input())
counter=0
while counter<n:
m=int(input())
print(m)
counter=counter+1

product of N inputs--------------------

n=int(input())
product=1
counter=0
while counter<n:
m=int(input())
product=product*m
counter=counter+1
print(product)

sum of the given numbers--------------------

n=int(input())
counter=0
sum=0
while counter<n:
m=int(input())
sum=sum+m
counter=counter+1
print(sum)

reads a word and prints each character of the word in a new line

Q:python---------------------------------------
A:p
y
t
h
o
n

a = input()
counter = 0
length_of_a = len(a)
while counter <=(length_of_a - 1):
print(a[counter])
counter = (counter + 1)

You might also like