I am currently writing a code that reads a file that contains "Did you win 100? Yes!", takes each character and converts it to its base 10 ASCII value, then converts the base 10 ASCII values to a user-inputted base 2-9. All characters that are not alphaNumeric are converted to ".."
I am not allowed to use built-in python functions to convert between bases, so I have written my own that divides the base 10 ASCII value by the new base and collects all of the remainders into a list and reverses the list so the new number is in the correct order.
My code is then supposed to write the new numbers and ".." to an out file, but I can't figure out how to format the list that goes to the out file. When I submit the code it says "builtins.TypeError: write() takes no keyword arguments". How can I write my list of remainders to an out file and be able to format it as a single string, without brackets and commas? Thanks!
infile = open("myFile.txt" , "r")
outfile = open("x_myFile.txt" , "w")
userBase = int(inputBase())
for line in infile:
for ch in line:
if ch.isalpha() or ch.isdigit():
value = int(ord(ch))
remainders = list()
while value>0:
remainders.append(value % userBase)
value//=userBase
remainders = remainders[::-1]
outfile.write(*remainders, sep='')
else:
outfile.write("..")
infile.close()
outfile.close()