CMSC 14200 4 Introduc!on to Computer

3天干完6个月的活,Claude把模型搬上AMD 一条挺刺激的消息:Anthropic 给投资人的材料里有一张幻灯片,写着它的 Claude Mythos Preview 只花了大约​,就摸清了怎么让另一个 Claude 模型在 AMD 的 MI355X 上跑起来。同一处还写了个对照数字:过去给一块新芯片做推理适配,通常要几十名工程师、​。3 天对 6 个月,这个比值太扎眼,当天中文互联网上就冒出一堆「英伟达的护城河塌了」的说法。我把能翻到的材料都翻了一遍,越看越觉得,塌掉的那一小块是真的,可塌的位置和很多人想的不一样。 阅读详情

CMSC 14200 4 Introduc!on to Computer 

Due: Thursday, January 30th at 4pm CT

The goal of this homework is to help you prac!ce working with graphs, and to gain further experience with GUI programming in pygame.

Ge"ng started

To test and submit your solu!on, you will need to pull some files provided by the instructors to your homework repository, and then add your code to three of

those files. Please start by naviga!ng to your coursework directory:

$ cd ~/cmsc14200-win-2025/coursework-GITHUB_USERNAME

Use git status to make sure that your repository is in a clean state. The output should look like this:

$ git status .

On branch main

Your branch is up to date with 'origin/main'.

If the output does not match, please review the relevant parts of the Git Basics tutorial. If you run into trouble, please ask for help.

Once you have cleaned up and are in a good state, run the following command:

$ git pull upstream main

(This command will pull the materials for this assignment into your local copy of your repository and will create a commit.)

Navigate to the hw3 directory that you just pulled and complete your work for this assignment in the files wordgraphs.py , test_graphs.py , and task5.py .

Tes!ng

As in the previous homework, we have provided automated tests for parts of this assignment. See How to Test your Solu!ons for a refresher on how to test

your code.

We strongly encourage you to use ipython3 to test your code by hand and to test your func!ons as you go.

As far as manually tes!ng your code in this assignment, the examples we provide assume that you have set up ipython3 to use autoreload and have

imported wordgraphs .

In [1]: %load_ext autoreload

In [2]: %autoreload 2

In [3]: import wordgraphs

Your Tasks

Adding type annota!ons

As in the prior homeworks, we expect you to add type annota!ons to the func!ons and methods you implement. You should add type annota!ons and

docstrings to any func!ons or methods you add, including any helper func!ons you choose to implement and any class methods you add.

You can typecheck your code for Tasks 1 through 4 at any !me like this:

mypy wordgraphs.py

You will generally want to check types any !me you implement a new func!on or method to check that you have added annota!ons correctly.

There are also some automated tests that will typecheck your code. This is explained in the “Type Checking” sec!on below.

Summary

These are the tasks in this assignment:

Task 1: complete RealWordsGraph class in wordgraphs.py

Task 2A: implement variants func!on in wordgraphs.py

Task 2B: write tests for variants in test_graphs.py

Task 3: implement shortest_word_path func!on in wordgraphs.py

Task 4A: complete PseudoWordsGraph class in wordgraphs.py

Task 4B: write tests for PseudoWordsGraph in test_graphs.py

Task 4C: complete RealWordsLazyGraph class in wordgraphs.py

Task 5: implement graph-drawing GUI in task5.py

Word Graphs

As we saw in class, graphs are a model and a type of data structure that allow us to represent en!!es and their rela!onships. These en!!es are o#en physical:

ci!es, people, or similar; with readily-imagined rela!onships like having transporta!on links, friendships, or the like.

But, we can work with more abstract en!!es and somewhat ar!ficial rela!onships as well. For instance, we might have a graph whose ver!ces correspond to

correctly-spelled words in the English language. What rela!onships might these more-conceptual en!!es have? Words might be linked by having a common

root in La!n, being from the same part of speech, or myriad other possibili!es depending upon what we are interested in.

Here is one defini!on of a rela!onship between words: two words are connected by an edge if they are of the same length, and exactly one of their le$ers is

different. For instance, “graph” and “grape” would be linked, or “node” and “code”, or “node” and “note”.

With this more abstract graph, the applica!ons may also be more abstract. But one could imagine using this kind of graph in support of some type of word

game, or perhaps as part of a spelling checker.

Task 1

The file graph.py contains an abstract base class for an undirected, unweighted graph whose ver!ces are strings. Given a vertex, we can find the set of

adjacent ver!ces, or the size of this set (the word’s degree). We can also ask whether a string represents a word that is actually in the set of real words used to

build the graph.

To complete this task, make an implementa!on of the class RealWordsGraph that inherits from the Graph base class. The constructor takes in the filename for a

list of words on which to base the graph, presumably from an English-language dic!onary. You should then populate an internal representa!on within the

object that treats each of the words in the input file as a vertex, and any two words of the same length that are only different in one of their le$ers as being

adjacent.

We do not specify the precise design of the data structure that you must employ, so long as you implement each of the methods in the class to func!on as

expected, and compute all the edges within the constructor. That said, think about a simple approach that stores all the needed informa!on using basic Python

data structures within a$ributes of the RealWordsGraph class; it is not necessary, and overly complicated, to adopt the mul!-class approach we saw in lecture

that used Vertex objects separate from a Graph class.

The specified file will contain one word per line. Because it will be computa!onally intensive to determine all the words that should share an edge in the graph,

the constructor takes a parameter for the maximum word length; skip any word longer than it. Also, skip any word that contains any character beyond the

twenty-six le$ers in the English alphabet; and change any upper-case le$ers to their lower-case equivalents.

We have provided the file web2 that contains all the words from the 1934 edi!on of Webster’s dic!onary. Because of its age, the copyright has lapsed, and this

file is included in some open-source opera!ng systems. Given the comprehensiveness of this data, you will find that it takes several seconds to build a graph

with words of length up to four, and a few !mes longer (on the order of half a minute) to build a graph with words of length up to five; hence, we recommend

you test your code star!ng with maximum lengths of three, then try four and five once your code appears to be working. (Please note that !mes are highly

dependent upon your computer and implementa!on details, so !mes close to the ones noted above, even if somewhat different, are not in and of themselves

cause for concern.)

Here is sample use of this class:

In [2]: g = wordgraphs.RealWordsGraph("web2", 4)

In [3]: g.is_word("code")

Out[3]: True

In [4]: g.is_word("abcd")

Out[4]: False

In [5]: g.adjacent("code")

Out[5]:

{'bode',

 'cade',

 'cede',

 'coda',

 'codo',

 'coke',

 'cole',

 'come',

 'cone',

 'cope',

 'core',

 'cote',

 'coue',

 'cove',

 'coze',

 'dode',

 'gode',

 'lode',

 'mode',

 'node',

 'rode',

 'tode',

 'wode'}

In [6]: g.degree("code")

Out[6]: 23

Remember that one difference between sets and lists is that sets do not have a no!on of order, so if your code produces the same set of adjacent words, but

they are printed in a different order, this is not a meaningful or worrisome dis!nc!on.

You can run the tests for Task 1 by using:

pytest -xvk task1 test_hw3.py

Task 2A

We could perform various analyses on this graph using breadth-first search. For instance, we might ask, given a word, what are the words that are a distance

of n away from that word in the graph? This would correspond to words that take a total of n modifica!ons to generate when star!ng at the specified word.

(These will usually be changes to n different le$ers in the word, but sequences that involve one or more changes to the same loca!on in the string would also

count, provided that no word appears mul!ple !mes as intermediate stages in the series of modifica!ons.)

Write the func!on variants that takes in a graph, a star!ng word, and a distance, and, using breadth-first search, produces the set of words exactly that many

edges away from the star!ng word. For instance, all of the words in the adjacency example shown earlier for Task 1 would cons!tute the answer for a star!ng

word of “code” and a distance of 1; and, for “code” and a distance of 2, one of the words would be “note” (because we can go from “code” to “node” and from

“node” to “note”). Given any word, only the word itself will be a distance of zero away from itself, and given a non-word, the set will be empty.

Here is sample use of this func!on:

In [7]: g = wordgraphs.RealWordsGraph("web2", 5)

In [8]: wordgraphs.variants(g, "abcde", 2)

Out[8]: set()

In [9]: wordgraphs.variants(g, "quake", 0)

Out[9]: {'quake'}

In [10]: wordgraphs.variants(g, "quake", 1)

Out[10]: {'quaky', 'quale', 'quare', 'quave'}

In [11]: wordgraphs.variants(g, "quake", 2)

Out[11]: {'huave', 'qualm', 'quark', 'quarl', 'quart', 'quire', 'suave'}

Again recall that set ordering is not meaningful.

Task 2B

Similarly to the prior assignment, we have only provided tests for some of the tasks in this homework, and you will write some of your own tests. We have

provided a test_graphs.py file in which you should write your tests for this task. Compared to Homework 2, we have given less detail about the tests you

should write. In par!cular, there are not empty func!ons in the test file, with specific descrip!ons for each test.

In the file test_graphs.py , write a series of func!ons whose names begin with test_task2_ and that test the variants func!on on a RealWordsGraph . For

reasons of performance, limit the maximum word length to three or four in your tests.

Here is a list of things you should test:

T0: that variants returns an empty set when given a word not in the dic!onary and a distance of at least one

T1: that variants yields a set consis!ng only of the given word when given a real word and a distance of zero

T2: that variants gives back the same set as adjacent would give, when given a real word and a distance of one

T3 and T4: tests for variants with real words and distances of two and three, respec!vely

In a comment for each of your test func!ons, write which requirement (T0, T1, T2, etc.) is fulfilled by a given test func!on.

To get the full benefit of tes!ng, you should determine the correct results of these tests manually, not merely by running your func!on and then se"ng its

answer as the expected result. How can you independently arrive at the correct answers for longer distances? You could for instance, use adjacent on a

star!ng word to get all the words one change away, then use adjacent on each of them, etc., in ipython3 , to work through the traversal by hand. You may also

be able to keep this task manageable by using unusually-spelled words that you expect will not have too many neighbors in the graph. If you adopt this kind of

approach, do be sure that your implementa!on of adjacent passes all the Task 1 tests first, so that you don’t base your test data here on incomplete or

incorrect adjacency informa!on.

Once you have implemented your test func!ons, you can type-check them like this:

mypy test_graphs.py

And run them like this:

pytest -xvk test_graphs.py

Please remember that there is no automated mechanism to check whether your tests are correct (i.e., there are no “tests for the tests”). The above command

will simply report whether or not your tests passed, not whether your tests were well-chosen or expected the correct output.

Task 3

A related ques!on to the above is, given two words, what is a path that, one le$er change at a !me, transforms the first word into the second, via other words?

In par!cular, what is the shortest path that does so, if any exists? When we think of shortest paths, we will o#en use Dijkstra’s shortest-paths algorithm, which

you have or will soon see in lecture; but, for unweighted graphs, breadth-first search is adequate and simpler.

Write the func!on shortest_word_path that takes in a graph, and source and des!na!on words, and using BFS, provides one of the shortest paths in the graph

between them, or None if no path exists. This path should be in order from the source to des!na!on, and include those words at its ends.

Here is sample use of this func!on:

In [9]: g = wordgraphs.RealWordsGraph("web2", 5)

In [10]: wordgraphs.shortest_word_path(g, "long", "path")

Out[10]: ['long', 'lone', 'lote', 'pote', 'pate', 'path']

Note that there are other legi!mate paths that your code might find instead. It would be acceptable if your code arbitrarily chose a different path among this list

of correct ones:

['long', 'lone', 'lote', 'pote', 'pate', 'path']

['long', 'lone', 'lote', 'late', 'lath', 'path']

['long', 'lone', 'lote', 'late', 'pate', 'path']

['long', 'lone', 'lane', 'pane', 'pate', 'path']

['long', 'lone', 'lane', 'late', 'lath', 'path']

['long', 'lone', 'lane', 'late', 'pate', 'path']

['long', 'lone', 'pone', 'pote', 'pate', 'path']

['long', 'lone', 'pone', 'pane', 'pate', 'path']

['long', 'pong', 'pone', 'pote', 'pate', 'path']

['long', 'pong', 'pone', 'pane', 'pate', 'path']

['long', 'pong', 'pang', 'pane', 'pate', 'path']

['long', 'tong', 'tang', 'tanh', 'tath', 'path']

You can run the tests for Task 3 by using:

pytest -xvk task3 test_hw3.py

Task 4A

The type of graph used in the previous tasks would be helpful for a word game, but not so much for a spelling checker: a#er all, the graph only contains

correctly-spelled words. We could instead consider a graph with all strings that contain only le$ers (real words or not), but with the same no!on of which

ver!ces are and are not linked by edges.

This graph could be problema!c in terms of memory use and performance, since there are exponen!ally-many “pseudo-words” (strings containing only le$ers)

of longer-and-longer lengths. But, we can employ a trick to manage this situa!on. Review the interface for graphs, embodied in the abstract base class. We are

only obligated to produce correct answers for each of the methods when asked to do so for a given vertex. In Task 1, we analyzed the set of words from an

English-language dic!onary and produced actual ver!ces and edges for later use. But, we could adopt a different approach en!rely: we could simply generate

answers on demand for a given string without actually having a durable internal representa!on of ver!ces and edges.

Implement the class PseudoWordsGraph as follows. Its constructor should take in the filename of a list of words, as with the earlier class. Read in these words and

store them internally (again filtering out words not consis!ng en!rely of le$ers, and conver!ng them to lower-case), but do not actually determine their

connec!ons or perform any other analysis in advance.

When asked for strings adjacent to a given string, produce all possible changes to the input string involving a single le$er. For instance, for the vertex “aaaa”,

one adjacent vertex would be “zaaa” and another would be “aama”. None of these are real words, but this graph conceptually consists of all strings that are

made only of le$ers, so each of these strings meets that defini!on. And, even though we have not constructed ver!ces and edges, so long as we have a way of

systema!cally producing all the other strings that are one change away from a given string, we have fulfilled the obliga!ons of the adjacent method. We

should also be able to compute the degree of a given vertex with a simple calcula!on.

For this class, the only reference to the dic!onary file is through the is_word method. Although any string consis!ng only of le$ers is a vertex in this graph, we

will only consider ver!ces that are actual words according to the provided file to be words for this par!cular method.

Having implemented this graph, we could use it in a spelling checker to suggest correctly-spelled words based on a misspelled word. If we have detected that a

string is not an actual word, we could use this graph to find all the variants one edge away from that string’s vertex that are actual words. If there are none, we

could next search for variants a distance of two away, and so on.

Modify your variants func!on to s!ll use any ver!ces returned by the adjacent method of the given graph in its traversal, but to only produce in its result set

ver!ces iden!fied as actual words by the is_word method. This modifica!on should not change results in any way when used with a RealWordsGraph , since all

ver!ces in such graphs are, in fact, real words. But, for PseudoWordsGraph objects, variants will now be able to explore through a path of intermediate nonwords before landing on a real one.

Here is sample use of this func!on with the new class:

In [11]: g = wordgraphs.PseudoWordsGraph("web2")

In [12]: wordgraphs.variants(g, "qbcde", 2)

Out[12]: {'abide', 'abode'}

Task 4B

You will also write tests for the PseudoWordsGraph class and its methods in the file test_graphs.py , in func!ons whose names start test_task4a_ .

Here is a list of things you should test:

T0, T1, and T2: that adjacent produces the correct set of strings when given an input string of length 1, 2, and 3, respec!vely, that is not an actual word

T3: that adjacent produces the correct results for a length-two input string that is an actual word

T4, T5, T6, and T7: that degree produces the correct number for the same scenarios as the corresponding test above numbered n-4 (i.e. T4 corresponds to

T0, T5 corresponds to T1, etc.)

T8 and T9: that is_word produces the correct result for a string that is (T8) and is not (T9) an actual word

Again write in a comment for each of your test func!ons which requirement is fulfilled by a given test func!on, and again independently write the correct

answers for comparison without merely copying the answers from your code. You can streamline the task of wri!ng a long list of adjacency answers by

genera!ng them within your test func!on via loops and making any needed modifica!ons to the results. To reduce the chances of making the same error in

your test logic as in your implementa!on, leading to a false sense of security, visually inspect any test data being generated by loops before relying on it.

Once you have implemented your test func!ons, you can type-check them like this:

mypy test_graphs.py

And run them like this:

pytest -xvk test_graphs.py

Task 4C

Recall that crea!ng an instance of a RealWordsGraph was slow. When it came !me to find all the edges between words of the same length, we had to do

something costly, like considering all pairs of words of the same length and whether an edge existed between them. This made working with a graph with

words of about length six or so unpleasantly slow, to say nothing of longer ones.

But, Task 4A contained an interes!ng and relevant insight: we do not necessarily need to precompute the en!re graph to be able to answer ques!ons about it.

In fact, a PseudoWordsGraph is arguably infinite, since we could ask ques!ons about the adjacent strings for strings of any length (100? 1,000? 10,000?). But, if

we only answer specific ques!ons about adjacency on demand rather than precompu!ng them, the infiniteness of the graph is immaterial.

Can we apply this same insight to the graph that consists only of real words? If we did, then we could avoid pre-genera!ng all the edges, which was costly.

Knowing all the edges in advance would only be beneficial if we expected to use this graph so much and for so long that we expected to eventually use most of

these edges at some point. But, if we only expect to use the graph for a few invoca!ons of variants and shortest_word_path , then it is not worth inves!ng the

!me in precompu!ng edges that we may never ul!mately touch.

For this task, implement a third graph class, RealWordsLazyGraph , which is, in some sense, a hybrid of the other two. Its constructor should only take in the name

of a word list file, but not a word length limit; the performance of this class will no longer make us want to impose such limita!ons. Con!nue to filter out words

that have non-le$er characters in them and con!nue to lower-case them. But, do not build an internal representa!on of the graph to the extent of actually

compu!ng the edges of the graph. It should be possible to implement RealWordsLazyGraph by making a copy of your code for PseudoWordsGraph and then

making a very small number of very small changes to this copy.

For the adjacent method, determine, on demand, which actual English words, based on the file loaded in the constructor, are one le$er modifica!on away

from the specified word. Because the informa!on has not been precomputed, as it was for RealWordsGraph objects, this determina!on will be slower than

calling adjacent on one of those graphs. But, since it only needs to consider the rela!onship between a single word and all others, rather than the rela!onships

between all pairs of words (as was needed to precompute a graph in a RealWordsGraph ), it will be faster to make the graph and then call adjacent a limited

number of !mes than it would be to precompute the en!re graph and call adjacent the same number of !mes.

Having implemented this graph correctly, you should be able to create an instance of the graph nearly instantaneously, but get the same results

from variants and shortest_word_path as you would for a RealWordsGraph . Further, you could get more ambi!ous with your tests, trying words of much longer

length:

In [2]: g = wordgraphs.RealWordsLazyGraph("web2")

In [3]: wordgraphs.shortest_word_path(g, "tricky", "normal")

Out[3]:

['tricky',

 'bricky',

 'bracky',

 'cracky',

 'cranky',

 'craney',

 'craner',

 'crater',

 'frater',

 'framer',

 'foamer',

 'former',

 'formel',

 'formal',

 'normal']

As before, either of these paths would be acceptable:

['tricky', 'pricky', 'prinky', 'pranky', 'cranky', 'craney', 'craner', 'crater', 'frater', 'framer', 'foamer', 'former', 'formel', 'formal', 'normal']

['tricky', 'bricky', 'bracky', 'cracky', 'cranky', 'craney', 'craner', 'crater', 'frater', 'framer', 'foamer', 'former', 'formel', 'formal', 'normal']

Your implementa!on is correct if it produces the same results as a RealWordsGraph would, but, instead of taking seconds to minutes to construct, calling the

constructor on a RealWordsLazyGraph returns effec!vely instantly. Although it is possible to use the timeit facility of ipython3 to evaluate run!mes precisely,

the difference should be so stark and the loading !me for a RealWordsLazyGraph no!ceably fast that precise !ming is not necessarily cri!cal.

You can run the tests for Task 4C by using:

pytest -xvk task4c test_hw3.py

Caching

You may have no!ced a downside of RealWordsLazyGraph and its approach to adjacent : if we call the adjacent method a second or subsequent !me with the

same vertex, it must compute the answer a second or subsequent !me from scratch. But, a RealWordsGraph would have computed this informa!on once, during

construc!on of the graph, and merely retrieve it each of the !mes it was asked. So, despite the long construc!on !mes, there are some possible benefits to that

design.

We could enhance our RealWordsLazyGraph to not perform repeated work unnecessarily. We could maintain an a$ribute in the object that tracks the answers

we have already computed, and check this a$ribute each !me we are asked for adjacency informa!on, before compu!ng it from scratch. For instance, the

a$ribute could be a Python dic!onary whose keys are strings and whose values are sets. The dic!onary would start out as empty. The adjacent method would

check the dic!onary and simply return the value for a given word, if present. If not present, it would compute the answer, and store it at that key in the

dic!onary before returning it. Should it be asked about the same vertex again, it will have the answer immediately the second and subsequent !mes.

It is possible to get even fancier with this idea to address concerns that might come up. For instance, if this dic!onary starts to take up too much memory, we

could selec!vely remove old or infrequently-accessed parts of it to save space, with the understanding that they could always be recomputed if need be.

You are not expected to add any of the op!miza!ons discussed in this subsec!on to your code, but we men!on it for your interest, especially since ideas like

this o#en come up when performing sophis!cated op!miza!ons for certain types of code. You will learn more about these topics in future courses.

Task 5

For this week’s GUI exercise, you will build a visualizer for complete graphs in task5.py . You can see a video demonstra!on here:

A complete graph K is an undirected graph of n ver!ces such that there is an edge connec!ng every pair of dis!nct ver!ces. The smallest complete graph with

a nonzero number of edges is K . Following the defini!on above, there are three edges in K , there are six edges in K , and so on. (A thought experiment: how

many edges are there in K for some integer i? It’s easily Google-able, but try to work out the answer on your own.) Note that K is the empty graph, and K is a

graph consis!ng of one vertex and zero edges (known as the singleton graph).

This week’s GUI task is to implement an applica!on that constructs an image of K for nonnega!ve integers $n$. The requirements of the GUI are minimal. It

must depict n ver!ces and the edges connec!ng every dis!nct pair of edges among them. It is not necessary to supply labels for the ver!ces; they can appear

on the screen as unlabeled dots or other shapes of your choosing. Also, the number of ver!ces must appear as a number somewhere in the GUI window. The

posi!on, size, color of this number is up to you. We have supplied four (open source) fonts in the assets/ directory for you to choose from.

When the applica!on opens, it must display K as well as the number 2. From there, your applica!on must support three keystrokes:

the up arrow must increase the number of ver!ces by one.

the down arrow must decrease the number of ver!ces by one, but never less than zero.

the q key must quit the applica!on.

While there is no upper limit on the hypothe!cal size of a complete graph, you may assume that we will not evaluate your work on any more than twenty

ver!ces (although once this tool is built, it is irresis!ble to mash the up arrow a million !mes and see what happens).

While we have chosen not to mandate exactly how your complete-graph figures should look, it is impera!ve not to arrange all of the ver!ces along one line

(except for a graph with only two ver!ces); this makes it impossible to see the edges connec!ng them. One way to arrange the ver!ces is equally spaced

around a circle; this is demonstrated in a video accompanying this task. The circular graph representa!on is not the only interes!ng display. Please experiment

and find an arrangement of ver!ces and edges that you find appealing.

Type Checking

While you have been doing some type-checking along the way, we’ve only been checking the files you have modified. We also need to make sure that there are

no type mismatches between the test code and your code. To do this, you will need to typecheck the test files themselves:

mypy test_hw3.py test_graphs.py

Doing this before you have a complete implementa!on will result in many type errors, so you want to wait un!l you have completed all the tasks before

running the above command.

Careful: any error reported by mypy will be the result of something wrong in your wordgraphs.py or test_graphs.py code. Never edit the test_hw3.py file to

make it pass the tests.

Finally, pytest will also type-check your code (which will be part of your Completeness score). To run those tests, run the following:

pytest -xvk mypy test_hw3.py

Grading

You will receive two S/N/U scores for this assignment: one for completeness and one for code quality.

Your completeness score will be determined solely on the basis of the automated tests, which provide a measure of how many of the tasks you have completed:

Grade Percent tests passed

Sa!sfactory at least 85%

Needs Improvement at least 55%

Unsa!sfactory less than 55%

For example, if your implementa!on passes 87% of the tests, you will earn a S (Sa!sfactory) score for correctness.

Submissions that pass 100% of the tests and achieve an S in Code Quality will receive an Excellent (E) in Completeness.

To find your score on the tests, first make sure you’ve run all the tests as follows:

$ pytest -v test_hw3.py test_graphs.py

Next, you can run the grader script like this:

$ python3 grader.py

Because there are no automated tests for Tasks 2B, 4B, and 5, your code quality score will be affected by how much func!onality you implement in Task 5 and

whether you adhered to the test requirements for Tasks 2B and 4B. As usual, it will also be based, in part, on your adherence to our Style Guide. Please note

that not implemen!ng Task 2B, 4B, or 5 at all will result in an N in Code Quality.

For your Code Quality score, we will be paying special a$en!on to the issues below. Submi"ng code with several of these issues will result in a score of N in

Code Quality. Addi!onally, please note that anything labelled as a “Major issue” will result in an automa!c score of N in your Code Quality.

[Task 1 - Major issue]: Your code should build a data structure where ver!ces are represented and there is explicit informa!on about which ver!ces have

edges to which other ver!ces.

[Task 2A]: You must not use any global variables in your implementa!on. Your implementa!on should use sets rather than lists where you are tracking a set

of items that does not need to be kept in any par!cular order and does not have duplicates.

[Task 2B - Major issue]: Your tests must actually perform the checks described in the list of tes!ng requirements. Small mistakes are fine, but you must not

make your tests pass by rote (e.g., by simply including something like assert True ).

[Task 3]: You must not use any global variables in your implementa!on. Your implementa!on should use sets rather than lists where you are tracking a set of

items that does not need to be kept in any par!cular order and does not have duplicates.

[Task 4A - Major issue]: Your code should not build a data structure with ver!ces for every possible string or precompute informa!on about edges between

ver!ces.

[Task 4A]: Your implementa!on of degree should use a simple calcula!on rather than actually genera!ng other strings and coun!ng.

[Task 4B - Major issue]: Your tests must actually perform the checks described in the list of tes!ng requirements. Small mistakes are fine, but you must not

make your tests pass by rote (e.g., by simply including something like assert True ).

[Task 4C]: Same as for Task 4A.

[Task 5 - Major issue]: Submi"ng the task5.py file without any modifica!ons (i.e., not implemen!ng Task 5 at all) is considered a major issue.

[Task 5]: You must implement the visualiza!on and each of the required behaviors.

[Task 5]: Your complete-graph visualiza!on must clearly display all ver!ces and all edges up to K .

[Style]: Your code must generally adhere to our Style Guide.

[Style]: Any new func!on you write must have a clear purpose that can be described in a sentence or two. Every func!on you write should also have a

proper docstring.

While these are the main things we care about in this assignment, please remember that it is not possible for us to give you an exhaus!ve list of every single

thing that could affect your code quality score (and that thinking in those terms is generally counterproduc!ve to learning how to program).

Cleaning up

Before you make your final submission, you should remove

any print statements that you added for debugging purposes and

all in-line comments of the form: “TODO”…” (these direc!ves typically start with ###). Further remove any raise NotImplementedError() lines once you have

completed the methods in which they resided (but not from an abstract base class).

Also, check your code against the style guide. Did you use good variable names? Do you have any lines that are too long?

Do not remove header comments, that is, the triple-quote strings that describe the purpose, inputs, and return values of each func!on.

Important: as you clean up, you should periodically save your file and run your code through the tests to make sure that you have not broken your code in the

process.

Submission

Once you have completed the required updates to wordgraphs.py task5.py , and test_graphs.py , you must submit your work through Gradescope under

“Homework #3”. Gradescope will fetch your files directly from your GitHub repository, so it is important that you remember to commit and push your work!

Under “Repository”, make sure to select your uchicago-cmsc14200-win-2025/coursework-GITHUB_USERNAME repository. Under “Branch”, just select “main”.

Finally, click on “Upload”. The Gradescope autograder will run three tools:

pylint to check for style issues. While this tool reports a numerical score, this score is not used to compute your SNU score on the homework. It may simply

alert you to style issues in your code.

mypy to type-check your code.

pytest to run the tests, which will determine your Completeness score.

Make sure to look at the score that is reported on the right sidebar. If 100 is reported as the score, you are done!

If your score is not what you expect, check to make sure you pushed your work to the server

如何处理动态语言(Python / JS)的“隐形”调用链? 本文揭示动态语言(Python/JS)中静态AST解析导致调用链“断链”的核心问题,提出通过运行时追踪补全图谱的解决方案。基于Code-Graph-RAG的cgr trace机制,分别利用pytest插件与V8 Profiler捕获真实调用路径,将动态边合并至静态图谱,并在权重体系中提升动态边优先级。实践表明,该方法可显著提升图谱覆盖率,实现“结构+行为”双视角理解代码,为MCP与Rerank系统提供可靠支持。 阅读详情

相关推荐

Playwright: Pytest vs Library vs LibraryAsync:三者如何选?

Python中Playwright的3个Target:Pytest(推荐用于E2E自动化测试,支持报告、并行、重试)、Library(同步脚本,适合爬虫与简单任务,需手动管理浏览器)、LibraryAsync(异步脚本,适用于高并发批量操作)。选择依据:测试项目选Pytest,轻量脚本选Library,高并发场景选LibraryAsync。

SmallBull的博客 227

本地化部署 DeepSeek,构建单细胞与空间转录组 AI 分析平台

本地化部署 DeepSeek,构建单细胞与空间转录组 AI 分析平台

weixin_53637133的博客 184

深入探讨 VQ-VAE:理解变分量化自动编码器

VQ-VAE代表"Variational Quantized Variational Autoencoder",是一种生成模型,通常用于处理高维数据,如图像和音频。它的设计灵感来自于变分自动编码器(VAE)和量化方法,结合了它们的优点,使得 VQ-VAE 能够生成高质量的数据,并在数据表示上引入离散性。VQ-VAE 是一种强大的生成模型,结合了变分自动编码器和量化方法的优点。它在图像和音频生成、数据压缩和生成性对抗网络等领域具有广泛的应用。

DeepViewInsight的博客 7017

【第 009 讲】全面掌握 Python 注释:注释的定义与作用 | 单行注释 | 三引号与多行注释 | 注释使用的最佳实践

本文系统讲解 Python 注释的完整知识体系:从注释的定义与作用讲起,梳理单行注释的书写位置、临时屏蔽用法与 PEP 8 排版规范,剖析注释被忽略的底层机制;进而说明三引号字符串的本质与嵌套问题;最后给出注释使用的三条实践原则,帮助读者写好可读性高的注释。

大模型全栈工程师 · Thanks_ks 1127

手把手配置:用Synopsys VDK为英飞凌TC4x系列MCU做虚拟原型开发

本文详细介绍了如何使用Synopsys VDK为英飞凌TC4x系列MCU进行虚拟原型开发,涵盖开发环境搭建、关键外设虚拟化配置、AUTOSAR栈集成及虚拟调试与性能调优全流程。通过虚拟原型技术,开发者可提前6-12个月启动软件开发,显著提升汽车电子项目的开发效率。

weixin_30606461的博客 293

新手避坑指南:用COMSOL Multiphysics仿真气体放电(汤逊vs.流注)

本文详细介绍了使用COMSOL Multiphysics仿真气体放电的实战指南,涵盖汤逊理论和流注模型的实现方法。通过对比两种放电模型的关键参数和物理场配置,帮助新手避免常见错误,准确预测气体击穿过程。文章还提供了工程应用案例,如高压绝缘子设计优化,展示了仿真技术在电力设备绝缘设计中的实际价值。

weixin_28716181的博客 479

AI全栈实战 | 3.9-01 爬虫入门:requests 加 BeautifulSoup 三分钟跑通,但 90% 的人栽在这 4 个“礼貌“问题上

⚠️:本文内容仅用于。请遵守目标站点的服务条款与相关法律法规,不得对目标服务造成负担,不得采集、传播个人隐私数据。技术是中性的,边界在你手里。爬虫的入门技术(requests 发请求 + BeautifulSoup 解析)三分钟就能学会。真正区分"会用爬虫"和"会做爬虫的人"的,是这篇我们跑通"请求→解析→存储"的最小闭环,然后重点把"合规与礼貌"这根弦给你绷上。

源码获取 | 运行部署 | 定制二开修改,如果回复不及时请耐心等待,请见谅。 441

2026.3.13:docker compose运行了Milvus 6个月,占用磁盘近138GB的原因

Docker容器运行Milvus半年后占用138GB磁盘空间,主要原因是容器日志无限增长、容器内写入大量数据未挂载到数据卷,以及未清理临时文件。通过检查发现超大容器目录569035582ce3...占用主要空间。解决方案是使用truncate命令清空容器日志文件(*-json.log),释放磁盘空间。建议配置日志轮转机制,并将数据挂载到宿主机数据卷以避免类似问题。

拥抱具身智能,昇腾Ascend C 194

Python 的 yield from 到底转发了什么:拆开 send、throw 和那个 return 值

很多人把yield from记成「省一层 for 循环的语法糖」。写和写,结果看着一样,于是就当它只是少敲几个字。这个理解会在三个地方翻车:调用方.send()的值送不进去、子生成器return的值拿不到、异常和close()传不下去。yield from真正做的事是,外层生成器退成一个透明通道。本文所有输出来自本机 CPython 3.13.14 实测。yield from不是循环,是委托——nextsendthrowclose四个方向的流量全部直通子生成器,并且子生成器return。

小小张说故事的博客 163

(4-2)A*

实际已经花费的代价(g(n)):从起点到当前节点n的实际路径代价。启发式估计的剩余代价(h(n)):从当前节点n到目标节点的估计路径代价。这是A算法的关键之一,启发式函数要足够接近实际代价,但又要高效计算。如果启发式函数等于0,A算法就相当于Dijkstra算法。实现A*算法的核心步骤如下所示。(1)初始化:将起点加入开放列表(open list),并将其f值设为g值和h值的和。(2)循环:从开放列表中选择具有最小f值的节点作为当前节点。如果当前节点是目标节点,算法结束;

码农三叔 1808

Java调用YOLOv26全解析:从ONNX模型部署到工业质检实战

本文分享了工业自动化领域使用Java调用YOLOv26进行零件缺陷检测的完整方案。通过YOLOv26s模型结合ONNX Runtime Java部署,误检率和漏检率显著降低(分别从12%降至2.1%,8%降至0.8%)。文章详细介绍了方案选型理由、环境配置避坑指南、ONNX模型导出步骤,以及Maven依赖配置(分CPU/GPU版本)。该方案直接在上位机Java环境中运行,避免了跨语言调用损耗,适合工业质检场景部署,提供了可复用的性能优化和多线程推理实现。

2601_94871597的博客 1110

从一段视频到可漫游的 4D 有声场景:思路拆解与最小复现手记

只需一段手机视频,你就能生成可"走进去"的 4D 有声场景:转头时狗叫声方向随之变化,走近时声音更清晰。本文拆解 Video-to-4DAVScene 的核心思路,手把手带你用几十行 Python 搭出最小管线,把视频中的运动物体变成带空间位置的声源,并附上三个真实踩坑的排障经验,代码可直接跑。🎧

helloagent的博客 246

SAP-ABAP:接口多继承与复合接口设计:复杂业务场景下的能力组合实现方案

本文介绍了ABAP中通过接口多继承与复合接口设计实现能力组合的方案。文章首先辨析了类实现多个接口与接口继承接口的核心概念,指出ABAP虽不支持类多继承,但可通过这两种机制灵活组合能力。随后详细讲解了类实现多个接口的语法规则与三种调用方式,并给出了五个基础能力接口的设计示例(日志记录、权限校验、数据导出、消息通知、格式转换)。作者通过对比单继承与接口多重实现的差异,强调后者在解耦和扩展性上的优势,为复杂业务场景下的能力组合提供了实用解决方案。

baidu_35680696的博客 250

【每天一个 Python 小案例30】Python 基础知识综合小项目:我的工具盒

作为系列收官,本篇把前 29 篇的知识点合成一个能直接用的命令行工具"我的工具盒":计算器(用 ast 解析表达式,不碰 eval)、单位换算与温度转换(一张换算表 + 特例分支)、记账与分类统计(Decimal + JSON 持久化)、以及用"字典当命令表"把菜单和业务逻辑解耦的主循环。文中对比了 eval 的安全隐患与 ast 白名单的做法,解释了 lambda 闭包在字典里的写法与晚绑定陷阱,并在最后给出整个系列的知识地图,把变量、数据结构、控制流、函数、类、异常、文件、标准库八块内容对应到具体篇目。

xinjiyaya的博客 432

[QMT和ptrade量化交易小白入门]-109、小市值选股的基础上用六脉神剑评分,回测年化可到132%

本专栏主要是介绍QMT和ptrade的基础用法,常见函数,写策略的方法,也会分享一些量化交易的思路,大概会写200篇左右。QMT的相关资料较少,在使用过程中不断的摸索,遇到了一些问题,记录下来和大家一起沟通,共同进步。

木头大左的博客 1872

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

双路径优化+双容差校准

默认使用向量化路径处理常规数据,当检测到内存非连续或需要极致短路性能时,自动切换至 Numba JIT 路径。“当 CI 宽度中位数为 $W$ 时,实际判定容差为 $10^{-12} + 10^{-9} \times W$"针对表征谱算子 2 的实际输出量纲(例如 $10^{-3}$ 至 $10^3$),调整。准确标记了哪些数组被复制。非短路、静默拷贝风险、量纲耦合容差),本方案重构了核心逻辑。,并完善审计元数据以记录内存拷贝状态。, 确保在不同量纲下判定标准的一致性。,否则需排查上游数据生成逻辑。

2301_77211362的博客 201

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

yolo 和 deft 算法的区别

你应该是打错了:是,不是 defrat;

曾大强博客 274

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级 备考:莫队算法离线区间查询详解

备赛进行时:第十八届蓝桥杯软件赛报名已于 2026-10-08 10:00 开启、12-18 14:00 截止,省赛定在 2027-04-10(C/C++·Python 程序设计 9:00–13:00);中国电子学会 2026 年 12 月软件编程(C/C++ 一级至十级、Python 一级至六级)考级报名 9/23–12/2 16:00、统考 12-12;全国青少年信息素养大赛 2026—2027 赛季算法应用主题赛也已进入复盘练兵窗口。

IT_Scratch的博客 183

两张表合并之后,行数悄悄多了一倍

pandas merge 行数异常膨胀源于右表键不唯一,导致数据静默复制。实测显示,未聚合的右表(756行)与左表合并后行数增至504行,合计膨胀3.5倍,但无报错。validate 参数仅在检查键唯一性时有效,one_to_one 和 many_to_one 可拦截问题,但需结合 duplicated() 前置检查。正确做法为先按键聚合右表,再合并,避免重复。建议合并前后核对行数、合计,并使用 indicator=True 排查匹配情况,确保数据一致性。

patrickstar231的博客 251

智慧农业实战:育秧车间秧盘计数与苗情分级的Python实现

首先,建立统一的数据结构,保存每盘秧苗的编号、批次、覆盖度、叶色得分和播种天数。A = "壮苗"B = "合格苗"C = "弱苗"@dataclassdays: int。

荆棘鸟智能的博客 138

我用 200 行代码写了个“代码屎山检测器“,扫完公司的老项目后我沉默了

这个工具不能帮你把屎山铲平,但至少能让你知道自己面对的是多大的山,也能在代码评审时用数据说话——“这个 PR 把圈复杂度从 12 推到了 18,能不能拆一下?毕竟,不能量化的东西,就没法改进。

xixiaoyunya的博客 272

Java Arrays.asList 常见坑详解|UnsupportedOperationException、数组联动、基本类型 bug

解析 Arrays.asList 常见开发陷阱,演示 UnsupportedOperationException、底层数组引用共享、基本类型数组问题,区分 Arrays 内部 ArrayList 与 java.util.ArrayList,给出数组转 List 的各种场景正确代码。

weixin_42617033的博客 510

【每天一个 Python 小案例29】Python 实现商品购物车

本篇实现一个购物车:商品目录、加入商品、修改数量、移除商品、查看小计、计算满减与 VIP 折扣、结算扣库存。核心设计是"目录与购物车分离"——目录存商品主数据,购物车只存 {商品编号: 数量};金额一律用 Decimal 并做 ROUND_HALF_UP 舍入。折扣部分讲清阶梯满减的匹配顺序(阈值从高到低、命中即停)与叠加顺序(先满减、后打折),并用一次完整结算演示 706 元如何变成 613.70 元。

xinjiyaya的博客 219

Python的字典

Python字典是存储键值对的数据结构,通过键(key)快速查找对应的值(value)。可使用{}定义,支持增删改查操作:通过dict[key]查询或修改值,get()方法安全获取并设置默认值,del dict[key]删除键值对,keys()、values()和items()用于遍历。items()结合双变量循环可高效遍历所有键值对,提升代码可读性与灵活性。

qq_43010954的博客 199

黄仁勋走了,护城河留下了什么

11 月 12 日,英伟达董事会批准黄仁勋辞去总裁、CEO 和董事职务,即刻生效,CFO 克雷斯出任临时 CEO;股价开盘一度跌 14.35%,收盘只跌 4.34%,市值单日蒸发 1820 亿美元;本文把「创始人走了护城河就没了」这个流行说法拆开——CUDA 还在,但 CUDA 正在被 Claude 三天凿穿,真正决定下一段路的是三个可以核对的东西:治理结构、决策机制、以及下一个百亿美元由谁拍板。

领码SPARK - 以无代码之星火,燎原数字之未来! 166

基于深度学习的工业表面缺陷检测系统-毕业设计

只用正常样本训练的工业表面缺陷检测系统:15 类工业品、5354 张图、73 种缺陷。PatchCore-lite 图像级 AUROC 0.896、像素级 0.951,单张 CPU 推理 115 毫秒;附 PaDiM 与整图基线对照,含 Django 系统、论文与使用文档。

csbysj2020 207
上一篇: CMU 18-879 instructions
下一篇: EC 391 - International Trade
wx____codehelp
博客等级 码龄2年 538粉丝 99原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值