I'm new to programming and currently working on problem #269 from r/dailyprogrammer. I want to add the ability to read files and format them based on the indention format given. My current code:
filename=input("What file would you like to reformat?")
for line in f:
if line.startswith('ENDIF') or line.startswith('NEXT'):
if line.startswith('FOR') or line.startswith('IF'):
FOR I=1 TO 31
IF !(I MOD 3) THEN
IF !(I MOD 5) THEN
IF (I MOD 3) && (I MOD 5) THEN
indents string ends with a newline, like this:
" \n". You want to get rid of that.
When reading from a text file, there will always be a newline character at the end of each line until you've reached the end of the file.
print() will also add a single newline to its output by default. If you don't want that, you can pass an
print('this line doesn't need another newline.\n', end='')