Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create Product.py
product of two numbers
  • Loading branch information
NormalVad authored Oct 25, 2020
commit 2f99bca77330ac43a5746fdcd20d799e97f7eac7
28 changes: 28 additions & 0 deletions day14/Python/Product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
@author: NormalVad
@date: 25/10/2020
"""

def product(a,b):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was another part to the question where you needed to calculate the sum of the digits of a number using recursion. Do include the solution to that in this Python script as well.

if(a==0 or b==0):
return 0
elif(b == 1):
return a
elif(a<0 and b<0):
a = a*(-1)
b = b*(-1)
return a + product(a,b-1)
elif(a>0 and b>0):
return a+product(a,b-1)
elif(a<0 and b>0):
a = a*(-1)
x = a+product(a,b-1)
return x*(-1)
else:
b = b*(-1)
x = a+product(a,b-1)
return x*(-1)

print("Enter two numbers to be multiplied seperated by a space")
(a,b) = list(map(int, input().split()))
print(product(a,b))