# Print greatest number amoung 500 number and their average excluding greatest number
import random
numbers = [random.randint(1, 1000) for _ in range(500)]
max_number = max(numbers)
filtered_numbers = []
index = 0
while index < len(numbers):
num = numbers[index]
if num != max_number:
filtered_numbers.append(num)
index += 1
average = sum(filtered_numbers) / len(filtered_numbers)
print("Maximum Number:", max_number)
print("Average (excluding maximum):", average)
---------------------------------------------------------------------------------------------
def factorial(n):
result = 1
for i in range(1, n + 1):
result *= i
return result
def isStrong(num):
original_num = num
sum_of_factorials = 0
while num > 0:
digit = num % 10
sum_of_factorials += factorial(digit)
num //= 10
if sum_of_factorials == original_num:
print(f"{original_num} is a strong number.")
else:
print(f"{original_num} is not a strong number.")
---------------------------------------------------------------------------------------------
def sum(n1, n2):
return n1 + n2
num1 = int(input('enter first num: '))
num2 = int(input('enter second num: '))
result = sum(num1, num2)
print(result)
---------------------------------------------------------------------------------------------
def area(l,b):
return l*b
length = int(input('length: '))
breadth = int(input('breadth: '))
print(area(length,breadth))
---------------------------------------------------------------------------------------------
def sumOfNumbers(n):
sum = 0
for i in range(n + 1):
sum += i
return sum
num = int(input('enter num : '))
print(sumOfNumbers(num))
---------------------------------------------------------------------------------------------
num = int(input("Enter a number: "))
temp = num
reverse_num = 0
while num > 0:
digit = num % 10
reverse_num = reverse_num * 10 + digit
num = num // 10
if temp == reverse_num:
print(f"{temp} is a palindrome.")
else:
print(f"{temp} is not a palindrome.")
---------------------------------------------------------------------------------------------
number = int(input("Enter a number: "))
original_number = number
num_digits = len(str(number))
sum_of_digits = 0
# Loop to calculate the sum of each digit raised to the power of the number of digits
while number > 0:
digit = number % 10
sum_of_digits += digit ** num_digits
number //= 10
# Check if the sum of digits is equal to the original number
if sum_of_digits == original_number:
print(f"{original_number} is an Armstrong number.")
else:
print(f"{original_number} is not an Armstrong number.")
Comments
Post a Comment