Assignments
Assignments
An Aron strong number is a number whose sum of digits raised to the power of the number of digits equals the
original number. Below is a Python program to check if a given number is an Aron strong number or not:
```python
def is_aron_strong(number):
num_str = str(number)
num_digits = len(num_str)
# Calculate the sum of digits raised to the power of the number of digits
if is_aron_strong(number):
else:
```
This program first defines a function `is_aron_strong` that takes a number as input and returns `True` if it's an Aron
strong number, otherwise `False`. Then it prompts the user to enter a number, checks if it's an Aron strong number
using the defined function, and prints the result.
2. Write a program in python to check whether a number entered by the user is palindrome or not.
You can use the following Python program to check if a number entered by the user is a palindrome or not:
```python
def is_palindrome(number):
num_str = str(number)
reversed_str = num_str[::-1]
if is_palindrome(number):
print(f"{number} is a palindrome.")
else:
```
This program defines a function `is_palindrome` that takes a number as input and returns `True` if it's a palindrome,
otherwise `False`. It then prompts the user to enter a number, checks if it's a palindrome using the defined function,
and prints the result.
3. Write a program in python to check whether a number krishnamurthi or not.
A Krishnamurthy number (also known as a Strong number) is a number that is equal to the sum of the factorials of its
digits. For example, 145 is a Krishnamurthy number because 1! + 4! + 5! = 1 + 24 + 120 = 145.
```python
def is_krishnamurthy(number):
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
num_str = str(number)
if is_krishnamurthy(number):
else:
This program first defines a nested function `factorial` to calculate the factorial of a number. Then, it defines the
`is_krishnamurthy` function, which takes a number as input and returns `True` if it's a Krishnamurthy number,
otherwise `False`. Finally, it prompts the user to enter a number, checks if it's a Krishnamurthy number using the
defined function, and prints the result.
Assignment- 5
You can use a simple loop to print the series of numbers from 1 to n. Here's a Python program to do that:
```python
def print_series(n):
print_series(n)
```
This program defines a function `print_series` that takes an integer `n` as input and uses a `for` loop to iterate from 1
to `n`, printing each number separated by a space. Finally, it prompts the user to enter the value of `n`, calls the
`print_series` function with that value, and prints the series.
```python
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
This program defines a recursive function `factorial` that takes an integer `n` as input and returns the factorial
of `n`. If `n` is 0 or 1, the function returns 1 (base case). Otherwise, it calculates `n * factorial(n - 1)` to compute
the factorial. Finally, it prompts the user to enter a number, calls the `factorial` function with that number, and
prints the result.
You can use a loop to generate the Fibonacci series in Python. Here's a program to do that:
```python
def fibonacci_series(n):
a, b = 0, 1
count = 0
if n <= 0:
elif n == 1:
print(a)
else:
print("Fibonacci series:")
nth = a + b
b = nth
count += 1
fibonacci_series(n)
```
This program defines a function `fibonacci_series` that takes an integer `n` as input and prints the Fibonacci series up
to the `n`th term. It initializes the first two Fibonacci numbers `a` and `b` to 0 and 1, respectively, and then uses a loop
to calculate and print the Fibonacci series. The loop runs `n` times to generate the series up to the `n`th term.