# function with argument
def isArmstrong(number):
original_number = number
num_digits = len(str(number))
sum_of_digits = 0
while number > 0:
digit = number % 10
sum_of_digits += digit ** num_digits
number //= 10
if sum_of_digits == original_number:
return True
else:
return False
result = isArmstrong(45)
if result:
print('it is armstrong')
else:
print('it is not armstrong')
# function without argument
def isArmstrong(number):
number = int(input('enter number: '))
original_number = number
num_digits = len(str(number))
sum_of_digits = 0
while number > 0:
digit = number % 10
sum_of_digits += digit ** num_digits
number //= 10
if sum_of_digits == original_number:
return True
else:
return False
result = isArmstrong(45)
if result:
print('it is armstrong')
else:
print('it is not armstrong')
# procedure without argument
def isArmstrong():
number = int(input("enter number: "))
original_number = number
num_digits = len(str(number))
sum_of_digits = 0
while number > 0:
digit = number % 10
sum_of_digits += digit ** num_digits
number //= 10
if sum_of_digits == original_number:
print(f"{original_number} is an Armstrong number.")
else:
print(f"{original_number} is not an Armstrong number.")
isArmstrong()
# procedure with argument
def isArmstrong(number):
original_number = number
num_digits = len(str(number))
sum_of_digits = 0
while number > 0:
digit = number % 10
sum_of_digits += digit ** num_digits
number //= 10
if sum_of_digits == original_number:
print(f"{original_number} is an Armstrong number.")
else:
print(f"{original_number} is not an Armstrong number.")
isArmstrong(145)
---------------------------------------------------------------------------------------------
def MaxTwo(num1,num2):
if num1>num2:
return True
else:
return False
n1 =int(input('enter first num: '))
n2= int(input("enter second num: "))
result = MaxTwo(n1,n2)
if result:
print("first number is greater")
else:
print("second number is greater")
---------------------------------------------------------------------------------------------
def MaxThree(num1, num2):
num3 = int(input('enter third num:'))
if num1 >= num2:
if num1 >= num3:
greatest = num1
else:
greatest = num3
else:
if num2 >= num3:
greatest = num2
else:
greatest = num3
print(f"The greatest number among {num1}, {num2}, and {num3} is: {greatest}")
n1 = int(input('enter first num: '))
n2 = int(input("enter second num: "))
MaxThree(n1, n2)
Comments
Post a Comment