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

Experiment 2

The document describes 5 Python programs: 1) a factorial program, 2) printing the first 7 multiples of 7, 3) checking if a triangle is a right angle using the Pythagorean theorem, 4) a nested loop pattern program, 5) filtering a sequence of binary numbers for those divisible by 5.

Uploaded by

Mahesh Kadambala
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)
11 views4 pages

Experiment 2

The document describes 5 Python programs: 1) a factorial program, 2) printing the first 7 multiples of 7, 3) checking if a triangle is a right angle using the Pythagorean theorem, 4) a nested loop pattern program, 5) filtering a sequence of binary numbers for those divisible by 5.

Uploaded by

Mahesh Kadambala
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/ 4

Name: K Mahesh

ID No: 2200030757
Sub: Python Lab

Experiment-02
1. Factorial of a Number
print("Enter a number to find factorial")
n=int(input())
fact=1
for i in range(1,n+1,1):
fact=fact*i
print(fact)

Output

2. First 7 multiples of 7
n=7
for i in range(1,8,1):
print(f"{n}*{i}=",n*i)
Output

1
Name: K Mahesh
ID No: 2200030757
Sub: Python Lab

3. Pythagorean Theorem
a=int(input())
b=int(input())
c=int(input())
if c*c==(b*b + a*a):
print("Triangle is Right angled triangle")
else:
print("Triangle is not Right angled triangle")
Output

4. Constructing a pattern by using nested loop


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

2
Name: K Mahesh
ID No: 2200030757
Sub: Python Lab

Output

5. Sequence of Comma separated 4 digit binary numbers and


divisible by 5
# Function to convert binary to decimal and check divisibility by 5
def binary_to_decimal(binary_str):
decimal_num = int(binary_str, 2)
return decimal_num % 5 == 0

# Input sequence of comma-separated binary numbers


binary_input = input("Enter a sequence of comma-separated 4-digit
binary numbers: ")

# Split the input into individual binary numbers


binary_numbers = binary_input.split(',')

# Filter numbers divisible by 5


divisible_by_5 = [num for num in binary_numbers if
binary_to_decimal(num.strip())]

3
Name: K Mahesh
ID No: 2200030757
Sub: Python Lab

# Print the result


print("Numbers divisible by 5:", ','.join(divisible_by_5))

Output

You might also like