bgetz
bgetz

Reputation: 21

Python Parsing Strings Assignment

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

Upvotes: 1

Views: 548

Answers (1)

Haran Rajkumar
Haran Rajkumar

Reputation: 2395

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.

Upvotes: 1

Related Questions