Answer to Question #288169 in Python for Matt

Question #288169

1. Write a program to print numbers in reverse order with a difference of 2, set the initial value to 10.


2. Write a program to print the sum of digits of any number entered by the user.


3. Write a program to find the product of digits to any number entered by user.


4. Write a program to find the factorial of any number.


5. Write a program to convert a binary number to a decimal number.

1
Expert's answer
2022-01-17T08:25:04-0500
num = 10
i = 2
while num >= 0:
    print(num)
    num = num - i

def getSum(n):
    
    sum = 0
    for digit in str(n): 
      sum += int(digit)      
    return sum
   
n = 12345
print(getSum(n))

def getProduct(n):
 
    product = 1
 
    while (n != 0):
        product = product * (n % 10)
        n = n // 10
 
    return product
n = 4513
print(getProduct(n))

# Python program to find the factorial of a number provided by the user.

# change the value for a different result
num = int(input('Enter integer here: '))

# To take input from the user
#num = int(input("Enter a number: "))

factorial = 1

# check if the number is negative, positive or zero
if num < 0:
   print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
   print("The factorial of 0 is 1")
else:
   for i in range(1,num + 1):
       factorial = factorial*i
   print("The factorial of",num,"is",factorial)

b_num = list(input("Input a binary number: "))
value = 0

for i in range(len(b_num)):
	digit = b_num.pop()
	if digit == '1':
		value = value + pow(2, i)
print("The decimal value of the number is", value)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS