Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk2 min

Massive Energy: What CS50P’s “Einstein” Teaches About Precision in Code

CS50P’s Einstein exercise specifies integer mass and energy. Here’s the short Python calculation, why integer arithmetic fits, and what precision means in this context.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For CS50P’s “Einstein” exercise, convert the entered mass to an integer and multiply it by 300,000,000 twice. That matches the assignment’s integer input and integer output—and avoids adding floating-point approximation where the task does not require fractional values. The arithmetic can be exact for the chosen integer constant, even though the exercise describes the speed of light as approximate.

What the CS50P Einstein exercise asks you to do

The course asks you to create einstein.py, prompt for mass in kilograms as an integer, and print the equivalent energy in joules as an integer. It introduces the equation E = mc² and uses an approximate speed of light of 300,000,000 meters per second. See the official CS50P assignment.

In the equation, E is energy, m is mass, and c is the speed of light. Since c is squared, multiply the mass by 300,000,000 two times. In Python, input returns text, so convert the response to an integer before doing the multiplication:

mass = int(input("Mass: "))
energy = mass * 300_000_000 * 300_000_000
print(energy)

Python permits underscores in integer literals to make long numbers easier to read; they do not change the value. The output is an integer, with no decimal point.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why integers fit this calculation

The assignment specifies an integer mass and an integer energy result. Python integers represent whole numbers exactly, and multiplying integer operands produces an exact integer result. That makes integer arithmetic a direct match for the exercise: no conversion to a floating-point value or rounding step is needed.

The manual examples on the assignment page are:

  • Mass of 1 kg produces 90,000,000,000,000,000 J.
  • Mass of 14 kg produces 1,260,000,000,000,000,000 J.
  • Mass of 50 kg produces 4,500,000,000,000,000,000 J.

These are the course’s published examples. The page also points learners to check50 for checking a submission.

Exact code arithmetic is not the same as an exact physical measurement

There are two kinds of precision to keep separate. The multiplication above is exact as integer arithmetic using the integer constant 300,000,000. But CS50P calls that speed of light value approximate, so the computed result should not be described as an exact measurement of the energy of a real object. The code is exact relative to the exercise’s chosen inputs and constant; the physical quantity is modeled using an approximation.

How this differs from floating-point arithmetic

Floating-point numbers are useful when a program needs fractional values, but they have different representation behavior. Python’s tutorial explains that most decimal fractions cannot be represented exactly as binary fractions; Python floats on almost all platforms map to IEEE 754 binary64 values with 53 bits of precision. As a result, a calculation using floats may contain a small representation approximation. See the Python tutorial’s explanation of floating-point arithmetic.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

That does not mean floats are inherently bad or should always be avoided. Use a numeric type according to the values and result a task requires. “Einstein” asks for whole-number input and output, so ordinary integers are simpler and meet the specification without an unnecessary representation change.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When Decimal might be appropriate instead

Python’s decimal module supports user-adjustable precision and can be useful when decimal equality rules matter, such as in some accounting work. The Python 3.11 documentation gives a default precision of 28 places. That is context for choosing a numeric representation, not a reason to add Decimal to this exercise: the specified values and result are integers. See the Python 3.11 Decimal documentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.