0% found this document useful (0 votes)
28 views2 pages

Assignment Python 5

Uploaded by

rushukumar11
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)
28 views2 pages

Assignment Python 5

Uploaded by

rushukumar11
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/ 2

# Q1. Write a program to print a table of a number input by the user.

n = int(input('Enter your number : '))

print(f"Multiplication Table for {n}:")


for i in range(1, 11):
print(f"{n} x {i} = {n * i}")

# Q2. WAP for finding the Factorial of a number.

# Function to calculate factorial


def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)

n = int(input("Enter a number: "))


result = factorial(n)

print(f"Factorial of {n} is {result}")

# Q3. WAP for converting Decimal to Binary.

def decimal_to_binary(n):
return bin(n).replace("0b", "")

number = int(input("Enter a decimal number: "))


binary_result = decimal_to_binary(number)

print(f"Binary representation of {number} is {binary_result}")

# Q4. WAP to check for Number Palindrome.

def is_palindrome(n):
return str(n) == str(n)[::-1]

number = int(input("Enter a number: "))


if is_palindrome(number):
print(f"{number} is a palindrome.")
else:
print(f"{number} is not a palindrome.")

# Q5. Write a Python program to find those numbers which are divisible by two values 7 and 5,
between 1500 and
# 2700 (both included). Make a generalized program to take all the inputs from the user.

def find_divisible_numbers(start, end, div1, div2):


return [num for num in range(start, end + 1) if num % div1 == 0 and num % div2 == 0]

start_range = int(input("Enter the start of the range: "))


end_range = int(input("Enter the end of the range: "))
divisor1 = int(input("Enter the first divisor: "))
divisor2 = int(input("Enter the second divisor: "))

divisible_numbers = find_divisible_numbers(start_range, end_range, divisor1, divisor2)


print(f"Numbers between {start_range} and {end_range} divisible by {divisor1} and {divisor2}:")
print(divisible_numbers)

# Q6. WAP to check Armstrong Number.

def is_armstrong(number):

num_str = str(number)
power = len(num_str)
return sum(int(digit) ** power for digit in num_str) == number

number = int(input("Enter a number: "))


if is_armstrong(number):
print(f"{number} is an Armstrong number.")
else:
print(f"{number} is not an Armstrong number.")

You might also like