#I created a program with two functions and a variable as follows:
#However, running this gives me an error:
Any help would be appreciated! Thank You guys so much!
def isHarshad(num): if num % sum([int(x) for x in list(str(num))]) == 0: return True else: return False def isSiete(num): String = str(num) Tens = len(str(num)) - 2 if String[Tens] == '7': return True else: return False Hodges = 14#Afterwards, I opened up a new program , imported the functions and opened a file (5000 random numbers) and was trying to read the file using the functions I made and imported:
from myLib import isHarshad, isSiete, Hodges f = open('Rumbers.txt', 'r') data = f.read() f.close() for i in data: if isHarshad(i) == True: print(i)
#However, running this gives me an error:
Error:File "/Users/Name/Desktop/Python/myLib.py", line 6, in isHarshad
if num % sum([int(x) for x in list(str(num))]) == 0:
TypeError: not all arguments converted during string formatting
#I'm a little stuck here and can't move forward - did I mess up the formatting by keeping the first function in a string when the data I'm trying to read is integers?Any help would be appreciated! Thank You guys so much!