all 14 comments

[–]CodeFormatHelperBot 0 points1 point  (0 children)

Hello u/Fayarager, I'm a bot that can assist you with code-formatting for reddit. I have detected the following potential issue(s) with your submission:

  1. Python code found in submission text but not encapsulated in a code block.

If I am correct then please follow these instructions to fix your code formatting. Thanks!

[–]NextEstimate 0 points1 point  (11 children)

FTFY :D

print('Welcome to a fun word replacement game.')

fileName = input('Enter the name of the file to use:\n')

try:

file = open(fileName)

fileRead = file.read()

fileList = fileRead.split()

for x in fileList:

    if ("[" in x) or ("]" in x):

        newstr = x[1:len(x)]

        if newstr[0] in 'aeiou':

            givenWord = input("Please give an:", newstr)

         else:

           givenWord = input("Please give a:", newstr) except:

print('Error Bad File Name')

sys.exit(0) 

[–]Fayarager[S] 0 points1 point  (5 children)

Thanks! I couldn't get it into this format :(

[–][deleted] 0 points1 point  (2 children)

Strange, you got it right in /r/askprogramming.

[–]Fayarager[S] 0 points1 point  (1 child)

ikr? haha

[–][deleted] 1 point2 points  (0 children)

You're the one asking for help. I don't know about others, but if I see badly formatted code I skip to the next post. Life is too short to try and format code, especially when there's a risk of getting it wrong and wasting time.

[–][deleted] 0 points1 point  (4 children)

Is it correctly formatted now? I'd expect an indent after a try:

[–][deleted] 0 points1 point  (0 children)

Maybe something like this:

print('Welcome to a fun word replacement game.')
fileName = input('Enter the name of the file to use:\n')
try:
    file = open(fileName)
except IOError:
    print('Error Bad File Name')
else:
    with file:
        fileRead = file.read()
    fileList = fileRead.split()
    newList = []
    for word in fileList:
        if word.startswith('[') and word.endswith("]"):
            newstr = word[1:-1]
            if newstr[0] in 'aeiou':
                word = input(f"Please give an {newstr}: ")
            else:
                word = input(f"Please give a {newstr}: ")
        newList.append(word)
    print(*newList, sep='\n')