0% found this document useful (0 votes)
8 views1 page

Python Loop Operations Tutorial

The document provides examples of basic loop operations in Python, including a while loop that counts up to a user-defined number, a for loop that prints numbers from 1 to a specified limit, and nested loops that create a pattern of asterisks based on user input for the number of rows. Each section includes code snippets demonstrating the functionality. The examples are designed to help users understand loop structures in Python programming.

Uploaded by

mahindrathar12
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)
8 views1 page

Python Loop Operations Tutorial

The document provides examples of basic loop operations in Python, including a while loop that counts up to a user-defined number, a for loop that prints numbers from 1 to a specified limit, and nested loops that create a pattern of asterisks based on user input for the number of rows. Each section includes code snippets demonstrating the functionality. The examples are designed to help users understand loop structures in Python programming.

Uploaded by

mahindrathar12
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

Implementation of Basic Program in Python- IV (Loop Operation)

# 1. while loop

n = int(input("Enter a number for while loop: "))

i=1

while i <= n:

print(i, end=" ")

i=i+1

# 2. for loop

m = int(input("\n\nEnter a number for for loop: "))

print("Numbers from 1 to", m)

for j in range(1, m + 1):

print(j, end=" ")

# 3. nested loops

rows = int(input("\n\nEnter number of rows for nested loop pattern: "))

print("Pattern:")

for x in range(1, rows + 1):

for y in range(1, x + 1):

print("*", end=" ")

print()

You might also like