Think of Congress like a college student. And major pieces of legislation like a term paper.

Months in advance the college kid knows when the paper is due. But, rather doing a little bit at a time, he waits until the night before the deadline to churn it out.

The paper, while far from perfect, ultimately gets done. And, that, in essence, is how Congress operates.

Faced with an immoveable deadline, House Republicans and Senate Democrats finally figured out a way to get a deal done — for the simple reason that the political stakes were simply too high (and too hard to predict) for one not to get done.

After the jump is our quick explanation on why both sides cut the deal.

Why Democrats compromised: Democratic politicians and party strategists know they are playing an away game in the eyes of most voters when they talk about debt and spending. A Pew poll released Thursday showed that 46 percent of those tested said the Republican party could do a better job of reducing the deficit while 34 percent opted for Democrats. (In an August 2009 Pew poll the two parties were basically deadlocked on the question.)

And remember that a foundational piece of President Obama’s political brand is his ability to make Washington work again. A shutdown would have been a difficult-to-erase symbol of failure on the same week the president began his re-election bid for 2012.

Why Republicans compromised: The bully pulpit a president enjoys is always an advantage in the political hurly-burly — yes, we said hurly burly — but especially in moments (like a government shutdown) when the public is actually paying attention. In the runup to the shutdown, Obama had already begun to cast the fight as between a grownup (him) and kids (Congress but especially Republicans in Congress.) “[The public] want[s] everybody to act like adults, quit playing games,”Obama told a crowd in Philadelphia at an energy event this week. Between the bully pulpit and Obama natural gifts as a communicator, Republicans were staring down the propect of repeating the mistakes committed by former House Speaker Newt Gingrich in his 1995 budget showdown with former President Bill Clinton.

And, in the final hours of the debate Republicans were losing the message war surrounding the inclusion of a rider to the bill that would have cut $363 million in federal funding for Planned Parenthood. Any failure to find compromise would have been cast by Democrats as evidence that the GOP let its social conservative ideology get in the way of a good deal. And that’s a political loser outside of the GOP base.