We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
There is an error with fptr.write(result + '\n').
Change it to fptr.write(str(result) + '\n').
The correct code is below.
def solve(n):
if 9 % n == 0:
print(9)
return 9
curr_str = ['9']
next_str = []
found = False
while not found:
for curr in curr_str:
a = curr + '0'
b = curr + '9'
if int(a) % n == 0:
print(int(a))
found = True
return int(a)
if int(b) % n == 0:
print(int(b))
found = True
return int(b)
next_str.append(str(a))
next_str.append(str(b))
curr_str = next_str
next_str = []
if name == 'main':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
result = solve(n)
# fptr.write(result + '\n')
# add str(result) because otherwise it does not work
fptr.write(str(result) + '\n')
fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Special Multiple
You are viewing a single comment's thread. Return to all comments →
There is an error with fptr.write(result + '\n'). Change it to fptr.write(str(result) + '\n'). The correct code is below.
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')