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

Loops Example

The document contains multiple code snippets demonstrating various programming concepts such as loops, input handling, and sorting algorithms. It includes examples for calculating totals from user input, finding the largest number, summing digits, printing patterns, and implementing bubble sort. Each section showcases different functionalities and outputs based on user-provided data.

Uploaded by

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

Loops Example

The document contains multiple code snippets demonstrating various programming concepts such as loops, input handling, and sorting algorithms. It includes examples for calculating totals from user input, finding the largest number, summing digits, printing patterns, and implementing bubble sort. Each section showcases different functionalities and outputs based on user-provided data.

Uploaded by

2003pathirakali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

j=0

while(j<3):
i=0
total = 0
while(i<6):
m = int(input("mark:"))
total = total + m
i=i+1
print("Total: ", total)
j+=1

mark: 90
mark: 90
mark: 90
mark: 9
mark: 90
mark: 90

Total: 459

mark: 99
mark: 99
mark: 99
mark: 99
mark: 99
mark: 99

Total: 594

mark: 88
mark: 88
mark: 88
mark: 88
mark: 88
mark: 88

Total: 528

j = 0
while(j<3):
i = 0
while(i<2):
print(i,j)
if(i==1):
break
i+=1

j+=1
0|1|2|
0
1
2

n = int(input("enter total inputs"))


large = -1
i = 0
while(i<n):
num = int(input("enter next num:"))
if(num>large):
large = num
i+=1
print("Largest", large)

enter total inputs 6


enter next num: 7
enter next num: 1
enter next num: 2
enter next num: 9
enter next num: 8
enter next num: 4

Largest 9

num = int(input("enter num:"))


sum = 0
while(num!=0):
digit = num%10
sum += digit
num = num//10
print(digit, end =" ")
print(sum)

enter num: 87686

6 8 6 7 8 35

rows= int(input("Enter no. of rows:"))


for n in range(1, rows+1):
for i in range(1,n+1):
print(i, end = ' ')
print()

Enter no. of rows: 5

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

arr = [5, 6, 7, 8, 4, 3, 2,10, 9, 1]


n = len(arr)
i=0
while(i<n):
j=0
while(j<n-i-1):
if(arr[j]>arr[j+1]):
t = arr[j]
arr[j] = arr[j+1]
arr[j+1] = t
j+=1
i+=1
print(arr)

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

You might also like