exam 7.1 starred - I didnt know they were gonna test with other dictionaries imputs

i got everything correct excepts for 7.1, because i didn't check for empty nodes cases, i thought the graph was not gonna change, like when they give us a cache, they are not suppose to change that.

do you think a person with this stupid errors can be a professional programmer? or a prof in any field?

asked 13 Apr '12, 16:18

maiza's gravatar image

maiza
2.1k215565
accept rate: 40%

What input does it say you failed on?

(13 Apr '12, 16:32) PeterUdacity ♦♦ PeterUdacity's gravatar image

6 Answers:

First off, of course they were going to try other inputs.

Second, if you learn from your mistakes and continue to you'll be fine. It's not like if you had got perfect scores on all the quizzes and homework assignments you would have been at the level of a professional programmer after this course anyway. This is just a beginning.

link

answered 13 Apr '12, 16:21

mhurron's gravatar image

mhurron
2.6k11135

Excellent answer on both counts :-)

(13 Apr '12, 16:30) JohanG-Sweden JohanG-Sweden's gravatar image

Like he said, you're just getting going. And yes, professional programmers make far "dumber" errors all the time :)

Learn the lesson! Consider fringe cases!

(13 Apr '12, 16:40) Adam Urato Adam%20Urato's gravatar image

Aushin was correct, your code returns ['g','g'] instead of ['g']:

output = [node] + graph[node] resolves to:

output = ['g'] + ['g']

edit: added missing quotation marks

edit2:

There's also a second situation in which case your code will not return the correct result

for an input like:
reachable({'c':['d'],'b':['c'],'a':['b']}, 'a')
it will return ['a','b','c'] instead of ['a','b','c','d']

because the first element will be checked when only ['a','b'] are in your output list, and it will not add 'd' as a result.

this is a bit tricky to test for, because since dictionaries are hash tables, the order of the entries might not actually be the one that you typed in, but it works to show the point with the input above.

link

answered 13 Apr '12, 19:37

Krzysztof%20E%20Butkiewicz's gravatar image

Krzysztof E ...
565

edited 13 Apr '12, 20:14

This doesn't sound right, @maiza , There was a question in the forum that Peter answered that they would not be testing for the case of an empty node. Check it out:
http://www.udacity-forums.com/cs101/questions/54709/exam-starred-question-1-what-is-the-expected-behaviour-if-the-node-is-not-in-the-graph

link

answered 13 Apr '12, 16:31

Susan%20Straub's gravatar image

Susan Straub
2.2k41747

this is the input that gives me an error, according to the tester machine

 graph = {'a': ['b', 'c'], 'c': ['b', 'd'], 'b': ['a', 'c'], 'e': ['a'], 'd': ['a'], 'g': ['g'], 'i': ['k'], 'k': []}, 'g'
link

answered 13 Apr '12, 16:42

maiza's gravatar image

maiza
2.1k215565

1

reachable(graph, 'g') returns ['g', 'g'] more than likely.

(13 Apr '12, 16:46) Adam Urato Adam%20Urato's gravatar image

and k? also they dont tell you witch node are they testing.

(13 Apr '12, 16:49) maiza maiza's gravatar image

somebody who got it right, tell me what this returns for all of entries.

(13 Apr '12, 17:05) maiza maiza's gravatar image

that's my case on 7.2 starred. got it right in 5 out of 6 cases ):

link

answered 13 Apr '12, 16:43

Radiohead's gravatar image

Radiohead
43251224

def reachable(graph, node):
    if node == '' or not node in graph:
        return []
    else:
        output = [node] + graph[node]
        for n in graph:
            if n in output: # add node
                for i in graph[n]:
                    if not i in output:
                        output += [i]
    return output

this is my code, maybe you can tell me what is wrong.

link

answered 13 Apr '12, 18:55

maiza's gravatar image

maiza
2.1k215565

Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15,261
×683
×172
×18
×11
×5

Asked: 13 Apr '12, 16:18

Seen: 305 times

Last updated: 13 Apr '12, 20:14