PLEASE REFER TO THE IMAGES FOR INSTRUCTIONS PLEASE USE STARTER CODE - CODE IN PYTHON3 ### starter code import random def spider_web(web_map, starting_place, destination): pass def spider_web_rec(web_map, starting_place, destination, visited): pass
PLEASE REFER TO THE IMAGES FOR INSTRUCTIONS
PLEASE USE STARTER CODE - CODE IN PYTHON3
### starter code
import random
def spider_web(web_map, starting_place, destination):
pass
def spider_web_rec(web_map, starting_place, destination, visited):
pass
def make_spider_web(num_nodes, seed=0):
if seed:
random.seed(seed)
web_map = {}
for i in range(1, num_nodes + 1):
web_map[f'Node {i}'] = []
for i in range(1, num_nodes + 1):
sample = random.sample(list(range(i, num_nodes + 1)), random.randint(1, num_nodes - i + 1))
print('sample', i, sample)
for x in sample:
if i != x:
web_map[f'Node {i}'].append(f'Node {x}')
web_map[f'Node {x}'].append(f'Node {i}')
return web_map
if __name__ == '__main__':
num_nodes, seed = [int(x) for x in input('Input num_nodes, seed: ').split(',')]
the_web = make_spider_web(num_nodes, seed)
print(spider_web(the_web, 'Node 1', f'Node {num_nodes}'))
Allowed Built-ins/Methods/etc
- Declaring and assigning variables, ints, floats, bools, strings, lists, dicts.
- Using +, -, *, /, //, %, **; +=, -=, *=, /=, //=, %=, **= where appropriate
- Comparisons ==,›, b, in
- Logical and, or, not • if/elif/else, nested if statements
- Casting int(x), str(x),float(x), (technically bool(x))
- For loops, both Pori and for each type.
- While loops
sentinel values, boolean flags to terminate while loops
- Lists, list(), indexing, i.e. try or myJist[3]
2d-lists if you want them/need them my_2d[i][j]
Append, remove o list slicing
- If you have read this section, then you know the secret word is: createous.
- String operations, concatenation +, +=, strip(), join(), upper(), lower(), isupper(), islower(), rjust(), ljust()
string slicing
- Print, with string formatting, with end= or sep=:
'{}'format(var),' %d% some_int, f-strings
Really the point is that we don't care how you format strings in Python
Ord, chr, but you won't need them this time.
- Input, again with string formatting in the prompt, casting the returned value.
- Dictionaries
- creation using dict(), or {}, copying using dict(other_dict)
- .get(value, not_found_value) method
- accessing, inserting elements, removing elements.
- Using the functions provided to you in the starter code.
- Using import with libraries and specific functions as allowed by the project/homework.
- Recursion
Forbidden Built-ins/Methods/etc
This is not a complete listing, but it includes:
- break, continue
- methods outside those permitted within allowed types
- for instance str.endswith
- list.index, list.count, etc.
- Keywords you definitely don't need: await, as, assert, async, class, except, finally, global, lambda, nonlocal, raise, try, yield
- The is keyword is forbidden, not because it's necessarily bad, but because it doesn't behave as you might expect (it's not the same as ==).
- built in functions: any, all, breakpoint, callable, classmethod, compile, exec, delattr, divmod, enumerate, filter, map, max, min, isinstance, issubclass, iter, locals, oct, next, memoryview, property, repr, reversed, round, set, setattr, sorted, staticmethod, sum, super, type, vars, zip
- If you have read this section, then you know the secret word is: argumentative.
- exit() or quit()
- If something is not on the allowed list, not on this list, then it is probably forbidden.
- The forbidden list can always be overridden by a particular problem, so if a problem allows something on this list, then it is allowed for that problem.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images