I think the error means that it is receiving some other data type although it expects another kind but i may be wrong since i am a beginner at python.Anyone knows how this can be fixed?
#Program to calculate factorial of a long number
def multiply(multiplier,multiplicand):
a = long(''.join(multiplier))
b = long(''.join(multiplicand))
a = a*b
multiplier = list(str(a))
b = b-1
multiplicand = list(str(b))
if(b == 1):
return False,multiplier,multiplicand
else:
return True,multiplier,multiplicand
num = ""
f = True # A flag variable
while(f): #checks if the string consists of digits only
num = raw_input("Enter number:")
f = False
if num.isdigit() == False:
print "oops,try again!"
f = True
multiplier = list(num)
multiplicand = multiplier[:]
multiplicand.pop()
multiplicand.insert(len(multiplier),str(long(multiplier[-1])-1)) #mand now contains multiplier -1 in list form
f = True
while (f):
f,multiplier,multiplicand = multiply(multiplier,multiplicand)
num = ''.join(multiplier)
print num #print the ans as a string
The code runs fine as long as the value entered is below 50,but after 50 it shows the error:
Traceback (most recent call last):
File "test.py", line 31, in <module>
f,multiplier,multiplicand = multiply(multiplier,multiplicand)
File "test.py", line 5, in multiply
b = long(''.join(multiplicand))
ValueError: invalid literal for long() with base 10: '5-1'
What does '5-1' mean?