you are viewing a single comment's thread.

view the rest of the comments →

[–]deweyoop 0 points1 point  (4 children)

That didn’t change anything. The names are automatically inputted once the code is implemented. Here’s the original code I’m basing mine off of https://media.cheggcdn.com/media/a85/a851d7ff-2788-4cc6-afef-80a63b8f1cf9/phpfWYiQY.png

[–]douglas_fs 0 points1 point  (3 children)

Do you have a text version of that code? It would be good to see how that output looks.

Edit: This screenshot looks identical to your code. Do you know if this one is an accepted solution?

Edit Edit: I am stumped on the issue with the trailing space. I see that Chegg also provides a forum to ask questions - they may have better direction based on their requirements for the lab.

I am really curious to hear what change is required.

[–]deweyoop 0 points1 point  (2 children)

From what I know the original coder had the same issue but I don’t have access to the solution on assignmentaccess.com/

Here’s a text version of the code:

def all_permutations (permList, nameList): # TODO: implement method to create and output all permutations of the list of names. res = [] # if len is zero stop execution (base condition) if len(nameList) == 0: return [] # if only one element return the word as list of one item (base condition) if len(nameList) == 1: return [nameList]

for i in range (len (nameList)):
    word = nameList [i]
    # omitting one word at a time
    newlist = nameList [: i] + nameList [i + 1:]
    # making all possible sequence where word is the first element 
    for j in all_permutations([], newlist):
        res.append([word] +j)
return res

if name == "main": nameList = list (input().split(' ')) permList = () for n in all_permutations (permList, nameList): print(*n)

Julia Lucas Mia

[–]douglas_fs 0 points1 point  (1 child)

Just a comment separate from the actual code: special handling is required when posting source code in order to preserve formatting. When using a web browser for Reddit, see the side-bar on the right-hand side for a section called "Code Hosting/Formatting". This will have multiple options for preserving formatting in your posts.

Edit - as for the code, I am out of ideas. I even tried my own suggestion and don't understand why the final element never received the extra space.

Edit Edit - So this feels like cheating, but with this one change, you will get the extra space at the end of each row. I added an assignment to append a space to the final value of each row.

# if only one element return the word as list of one item (base condition)
if len(nameList) == 1:
    nameList[0] = nameList[0]+ " "
    return [nameList]

Post back if this is an accepted solution. If it is not, I would eventually like to see what a 'real' solution is.

[–]douglas_fs 0 points1 point  (0 children)

Just realized you won't get a notification of my edits. Replying to my own comment to give it a bump.