write a program to check whether a number is a special 2-digit number or not. A Special 2-digit number is such that when the sum of its digits is added to the products of its digits the result is equal tot he original 2-digit number
Question
write a program to check whether a number is a special 2-digit number or not. A Special 2-digit number is such that when the sum of its digits is added to the products of its digits the result is equal tot he original 2-digit number
Solution
Sure, here is a Python program that checks whether a number is a special 2-digit number or not.
def check_special(num):
if num < 10 or num > 99:
return False
else:
sum_of_digits = num // 10 + num % 10
product_of_digits = (num // 10) * (num % 10)
if sum_of_digits + product_of_digits == num:
return True
else:
return False
# Test the function
num = int(input("Enter a two digit number: "))
if check_special(num):
print(num, "is a special 2-digit number.")
else:
print(num, "is not a special 2-digit number.")
This program first checks if the number is a 2-digit number. If it is, it calculates the sum and the product of the digits and checks if their sum is equal to the original number. If it is, the function returns True, indicating that the number is a special 2-digit number. If not, it returns False.
Similar Questions
Alex is teaching a class on number properties and wants to create an exercise for his students. He needs a program that takes a three-digit number as input, calculates the sum of its digits, and determines whether the sum is even or odd.
A number is said to be a crazy number if the sum of its digits is equal to the product of its digits. How many two-digit crazy numbers exist?
The difference between a 2-digit number and the number obtained by interchanging the positions of the digits is 54.Consider the following statements:1. The sum of the two digits of the number can be determined only if the product of the two digits is known.2. The difference between the two digits of the number can be determined.Which of the above statements is/are correct?
The sum of the digits of a two-digit number is 9. If 27 is addedto it, the digits of the number get reversed. The number is
Sum of the digits of a two-digit number is 9.When we interchange the digits, it is found that the resulting new number is greater than the original number by 45.What is the two-digit number?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.