0% found this document useful (0 votes)
5 views6 pages

Exp 2

The document contains multiple Python programs that demonstrate various functionalities. It includes programs to print prime numbers within a specified interval, calculate the average and square of a list of numbers, display patterns using nested loops, and compute the sum of specific series. Each section provides code snippets along with expected outputs.

Uploaded by

sanoopsamson77
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)
5 views6 pages

Exp 2

The document contains multiple Python programs that demonstrate various functionalities. It includes programs to print prime numbers within a specified interval, calculate the average and square of a list of numbers, display patterns using nested loops, and compute the sum of specific series. Each section provides code snippets along with expected outputs.

Uploaded by

sanoopsamson77
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
You are on page 1/ 6

1. Print all prime numbers with an interval.

lower_value = int(input("Enter starting interval: "))


upper_value = int(input("Enter ending interval: "))

print("The Prime Numbers in the range are:")


for number in range(lower_value, upper_value + 1):
if number > 1:
for i in range(2, number):
if (number % i) == 0:
break
else:
print(number)

OUTPUT

2. Input a list of n numbers, calculate and display the average of


numbers. Also display the square of each value in the list.
n = int(input("Enter n Numbers :"))
lst=[]
sum=0
square=[]

for i in range(n):
a= int(input("Enter Number"))
lst.append(a)
sum+=a

print(f"\nAvg {sum/n}")

for i in range(n):
square.append((lst[i])*lst[i])

print(f"squared list: {square}")

OUTPUT
3. Write a program to display the following patterns using nested
loops.

a =int(input("Enter"))

for i in range(1,a+1):
for j in range(i):
print(i,end=' ')
print()

OUTPUT

a = int(input("Enter"))

for i in range(1, a + 1):


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

OUTPUT

a = int(input("Enter"))

for i in range(1, a + 1):


for j in range(i, 0, -1): # Start from i, go down to 1
print(j, end=' ')
print()

OUTPUT
4. Write a program to print the sum of the following series

a.

n = int(input("Enter the value of n: "))


total = 0

for i in range(1, n + 1):


total += 1 / i

print("The sum of the series is:", total)

OUTPUT

b.

n = int(input("Enter the value of n: "))


total = n * (n + 1) // 2
print("The sum of the series is:", total)
OUTPUT

You might also like