0% found this document useful (0 votes)
220 views4 pages

Arrays and Loops

This document contains summaries of 12 code snippets: 1) Finds the largest palindrome made by multiplying two 3-digit numbers 2) Checks if a sum of numbers is divisible by a given number K 3) Calculates the sum of numbers multiplied by their index 4) Prints the input number if its sum is even, else prints one less 5) Prints letters in a triangle pattern with increasing rows 6) Separates even and odd numbers into different lists 7) Calculates the factorial of a number and sums the digits 8) Prints pentagonal numbers up to a given index 9) Prints numbers in increasing rows with a number repeated on each row 10) Prints triangles of stars of increasing size up

Uploaded by

Ananya Singh
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)
220 views4 pages

Arrays and Loops

This document contains summaries of 12 code snippets: 1) Finds the largest palindrome made by multiplying two 3-digit numbers 2) Checks if a sum of numbers is divisible by a given number K 3) Calculates the sum of numbers multiplied by their index 4) Prints the input number if its sum is even, else prints one less 5) Prints letters in a triangle pattern with increasing rows 6) Separates even and odd numbers into different lists 7) Calculates the factorial of a number and sums the digits 8) Prints pentagonal numbers up to a given index 9) Prints numbers in increasing rows with a number repeated on each row 10) Prints triangles of stars of increasing size up

Uploaded by

Ananya Singh
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
You are on page 1/ 4

Palindromic number reads the same both ways

n=int(input())
largest_palindrome=0
for i in range(100,n):
for j in range(100,n):
p=i*j
if str(p) == str(p)[::-1] and p>largest_palindrome:
largest_palindrome=p
print(largest_palindrome)

Special Task Force Sed


N,K=map(int, input().split())
numbers=list(map(int, input().split()))
sumofnum=sum(numbers)
if sumofnum%K==0:
print(0)
else:
print(1)

Tina likes arrays


n=int(input())
sum=0
for i in range(1,n+1):
sum=sum+(int(input())*i)
print(sum)

You are given an Integer N. Consider the sequence


n=int(input())
sum=0
for i in range(0,n+1):
sum=sum+i
if sum%2==0:
print(n)
else:
print(n-1)

Institution celebrates independence day. Our NCC


n=int(input())
letters=[input() for i in range(n)]
for j in range(n):
row=[]
for k in range(j+1):
row.append(letters[k]+' ')
for l in range(n-j-1):
row.append('')
print(''.join(row))

Thanos and Iron man


n=int(input())
odd=[]
even=[]
for i in range(n):
a=int(input())
if a%2==0:
even.append(a)
else:
odd.append(a)
print(*even, end=' ')
print()
print(*odd, end=' ')
print()

n! means n x (n-1)….
import math
n=int(input())
fact=math.factorial(n)
sum=0
for i in str(fact):
sum+=int(i)
print(sum)

Pentagonal numbers
n=int(input())
for i in range(1,n):
num=int(i*(3*i-1)/2)
print(num)

Yogesh booked ticked


n=int(input())
for i in range (1,n+1):
for j in range(i):
print(i,end=" ")
print()

Battle of Kurukshetra
n=int(input())
for i in range(1,n+1):
print("* "*i)

Laaysa with his friends


rows = int(input())
for i in range(1, rows + 1):
num = 1 if i % 2 != 0 else 2
for j in range(1, i + 1):
print(num, end=' ')
num += 2
print()

You might also like