1

Hi this is my first post. I am working on homework for my Python course. I have my code nearly complete, however I am having an issue with a line break. I have three pictures showing my results when I submit for the grade. My theory is this is an issue with my loop and that I will need to add a break or change the structure somehow. If you could please also point me in the right direction and not give me the answer for free it would be appreciated. Thank you very much.

https://i.sstatic.net/812uv.jpg https://i.sstatic.net/bbTfp.jpg https://i.sstatic.net/kV3Z6.jpg

I also have my code below:

string = input('Enter input string: ')

while string != 'q':
    if ',' not in string:
        print('\nError: No comma in string.')

    else:
        string = string.replace(' ','')
        string_parts = string.split(',')

        print('\nFirst word: %s' % string_parts[0])
        print('Second word: %s' % string_parts[1])

    user_input= input('Enter input string: ')
    string = user_input
3
  • 1
    Are the indents in your code block exactly the same as what you have in your scripts? Commented Apr 3, 2019 at 1:59
  • Apologies I will try and edit my first post, here is what it looks like in the work book: imgur.com/oBy241X Commented Apr 3, 2019 at 2:01
  • You have two places where you are explicitly printing a newline ('\n') character. Do you want to do that? Have you tried taking those out? To print a blank line, you can call print with no argument, like print(). Try putting one or more of those in places where your instructor wants to see spaces in the output. Commented Apr 3, 2019 at 2:18

1 Answer 1

1

Comparing, your output and the expected one, I find the only difference to be the absence of the newline (\n) in yours. I don't think there is any problem with the structure of the loop.

Observe where the instructor requires you to put the newlines and just add them in the relevant parts of your loop.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I returned to the problem and tried entering some newlines based on your tip and got full credit for the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.