Washington • Cheating isn’t winning. We try to teach this to our children, but politics provides the opposite lesson.

Political cheating allows those who engage in it to amass far more power than they have a right to in a constitutional democracy. Its most sophisticated form isn’t ballot-box stuffing but the use of indirect means by those in authority to perpetuate themselves in office.

Within 48 hours, Americans were offered two fast courses in the politics of cheating.

Late Monday, the Trump administration — acting against the advice of six previous Census Bureau directors, Republicans and Democrats alike — moved to add to the 2020 census a query about a respondent’s citizenship status.

And on Wednesday, the Supreme Court heard a case that turns on whether Maryland’s gerrymandered district boundaries deprive Republicans of fair representation in Congress.

In both cases, the courts should act to defend our republican democracy. On the census controversy, Congress could also provide a remedy. But most Republicans are likely to be quite happy with the distortions that the citizenship question could introduce into our decennial head count.

There’s a reason why the formal census has not asked about citizenship since 1950, and why it is an especially bad idea to reintroduce it now.

Response rates to the census in lower-income neighborhoods have long been a challenge, and immigrants in the country illegally have worried that answering the questionnaire could endanger their status, despite legal guarantees of confidentiality. Even legal immigrants have shared these worries.

Such concerns have increased exponentially with President Trump targeting undocumented immigrants with a proud and public ferocity.

The undercounting of immigrants would create a twofold injustice. It would tilt representation at all levels of government away from places with large populations of Latinos and other immigrants (often Metropolitan and Democratic-leaning) and overrepresent white, rural regions and states. And it would short-change undercounted areas when it comes to federal funds, since many programs operate on formulas based on the census.

In the Trump era, there is an irony here since one legitimate concern in locales with high levels of recent immigration is that their public services are often strained. Cutting money from such jurisdictions only increases the burdens on local taxpayers, native born and immigrant.

The maneuver is all the more problematic because Commerce Secretary Wilbur Ross chose to include the request for information on citizenship in the face of objections from career Census Bureau officials. The lateness of his decision means the citizenship question will not be subjected to the Bureau’s usual extensive testing for the effect of new inquiries on the accuracy of the overall count.

This is one key contention of the lawsuit from California Attorney General Xavier Becerra, who said Ross’ decision was “arbitrary and capricious.” He’s right. California is one of at least 12 states trying to block the move.

And political cheating at its purest and most obvious is gerrymandering, drawing district lines to maximize your party’s representation in legislative bodies and minimize the number of seats your opponents can win.

Because so many of the state legislatures that drew district lines after the 2010 Census were controlled by Republicans, an end to gerrymandering now would be especially challenging to the GOP. So opposing gerrymandering has come to be seen as a partisan, Democratic issue.

But it’s not. The addition of the Maryland case to a docket that already includes a challenge to an outlandish GOP gerrymander in Wisconsin is a reminder that both parties can suffer from this practice.

In Maryland, a formerly Republican district based in the rural and western parts of the state was chopped up, its pieces redistributed in a way that reduced the GOP to only one seat in the state’s eight-member House delegation.

Linking Maryland and Wisconsin could allow the Supreme Court to rule against gerrymandering nationwide in a thoroughly non-partisan way. And the Wisconsin litigants provided an objective formula for judging when district lines are plainly unfair. Justice Stephen Breyer’s suggestion Wednesday that the court kick the matter into a later term is worth pursuing only if it could lead to a comprehensive ruling against gerrymandering.

Attacks on judicial activism are a staple on the right. The increasingly aggressive activism of conservative judges has made this a live concern on the left as well. But when elected officials use their power to make it ever harder for their opponents to win elections — exactly what’s happening with the census and gerrymandering — the courts have an obligation to serve as democracy’s last line of defense.

E.J. Dionne