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

Class XI Practical Programs

The document contains code snippets that demonstrate: 1) Taking 3 user input numbers and determining the largest; 2) Checking if a user input number is perfect, Armstrong, or a palindrome; 3) Determining if a user input number is prime or composite; 4) Generating terms of the Fibonacci series up to a user input number; 5) Computing the greatest common divisor of two user input integers.
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)
10 views2 pages

Class XI Practical Programs

The document contains code snippets that demonstrate: 1) Taking 3 user input numbers and determining the largest; 2) Checking if a user input number is perfect, Armstrong, or a palindrome; 3) Determining if a user input number is prime or composite; 4) Generating terms of the Fibonacci series up to a user input number; 5) Computing the greatest common divisor of two user input integers.
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

Q.Input three numbers and display the largest/smallest number.

#input first,Second and third number


num1=int(input("Enter First Number"))
num2=int(input("Enter Second Number"))
num3=int(input("Enter Third Number"))
#Check if first number is greater than rest of the two numbers.
if (num1> num2 and num1> num3):
print("The Largest number is", num1)
#Check if Second number is greater than rest of the two numbers.
elif (num2 > num1 and num2> num3):
print ("The Largest number is", num2)
else:
print ("The Largest number is", num3)

Q .Determine whether a number is a perfect number,an Armstrong number


or a palindrome.
def is_perfect_number(number):
divisors = [i for i in range(1, number) if number % i == 0]
return sum(divisors) == number

def is_armstrong_number(number):
num_str = str(number)
num_digits = len(num_str)
digit_sum = sum(int(digit) ** num_digits for digit in num_str)
return digit_sum == number

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

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

if is_perfect_number(number):
print(f"{number} is a perfect number.")
else:
print(f"{number} is not a perfect number.")

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

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

Q Input a number and check if the number is a prime or composite number.


def is_perfect_number(number):
divisors = [i for i in range(1, number) if number % i == 0]
return sum(divisors) == number

def is_armstrong_number(number):
num_str = str(number)
num_digits = len(num_str)
digit_sum = sum(int(digit) ** num_digits for digit in num_str)
return digit_sum == number

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

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

if is_perfect_number(number):
print(f"{number} is a perfect number.")
else:
print(f"{number} is not a perfect number.")

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

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

Q Display the terms of a fibonacci series.


def fibonacci_series(n):
fib_series = [0, 1]
for i in range(2, n):
next_term = fib_series[i - 1] + fib_series[i - 2]
fib_series.append(next_term)
return fib_series

# Input the number of terms


num_terms = int(input("Enter the number of terms in the Fibonacci series: "))

if num_terms <= 0:
print("Please enter a positive integer.")
else:
series = fibonacci_series(num_terms)
print("Fibonacci Series:")
for term in series:
print(term, end=" ")

Q Compute the greatest common divisor of two integers.


import math
# Input two integers
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
gcd = math.gcd(num1, num2)
print(f"The greatest common divisor of {num1} and {num2} is {gcd}.")

You might also like