Build a Surface Roughness Calculator

Build a Python notebook that reports surface roughness improvements.

Introduction

30 Second Summary

A polished metal surface can look smoother after treatment. Your eyes cannot tell you exactly how much its texture changed.

In this project, you will build a surface-roughness calculator with Python in Google Colab. It turns measurements from before polishing plus after polishing into a labelled engineering report.

What You'll Build

Picture your notebook turning two Ra readings into a report that shows a 1.42 µm reduction plus a 77.2% improvement.

By the end of this project, you'll have:

  • A browser-based Python notebook that runs without a local Python installation.
  • A surface-change calculation that produces the absolute Ra reduction. It also calculates the project-defined percentage improvement.
  • A readable engineering report that identifies the sample plus its polishing process. Its measurements include µm units. Its results use controlled decimal precision.
  • Secret Mission: Extend the calculator from Ra to Rq. Validate the new rounded results.

Are there any prerequisites?

No prior Python experience is required. Your Google Drive notebook supports the Windows-first workflow plus Android access.

Before We Start

Your calculator will live in a browser-based notebook. A missing browser or account would stop you before your first Python instruction runs.

This step confirms that Google Chrome is available on your chosen device. You will also prepare a Google Account and define the measurement comparison that guides the program.

In this step, get ready to:
  • Make Google Chrome available on your chosen device.
  • Prepare a Google Account for the notebook workspace.
  • Define the comparison your surface-roughness calculator performs.
Prepare Google Chrome

Windows gives you more room for writing code. Use it as your primary coding device when it is available.

Android provides another way to reach the browser-based workspace when Windows is unavailable.

  • Press the Windows key on your Windows computer to open the search bar.
  • Type Chrome into the search bar.
  • Select Google Chrome if it appears.
  • Use your Android app search to find Chrome when Windows is unavailable.
  • Select the tab that matches your result.

✔️ Chrome opens on my chosen device

  • Select Windows as your primary coding device when it is available.
  • Select Android as your coding device when Windows is unavailable.

Chrome opens in its own window. Your browser is ready for the notebook workspace.

ⓧ Chrome is missing on Windows

The Windows installation uses a downloaded file. The installer guides you through the remaining setup.

  • Open Google's Chrome installation guide in another available browser.
  • Download the Chrome installation file for your Windows computer.
  • Run the downloaded installation file.
  • Follow the on-screen prompts.
  • Press the Windows key when the installation finishes.
  • Type Chrome into the search bar.
  • Select Google Chrome from the search results.

Chrome opens in its own window. Your Windows computer is now the primary coding device for this project.

ⓧ Chrome is missing on Android

The Play Store provides the installation path for Android.

  • Open the Play Store on your Android device.
  • Search for Chrome.
  • Tap Install.
  • Tap Open when the installation finishes.

Chrome opens on your Android device. You can now use this device for the browser-based project.

Chrome Still Not Opening?

  • Rerun the downloaded installation file on Windows.
  • Confirm that your Android device has an Internet connection.

Ask for help without sharing personal account details: Help me get Chrome open on my device.

You have cleared the first practical hurdle. Chrome is ready to carry your project into its browser-based workspace.

Prepare a Google Account

The notebook you create next is stored in Google Drive. Your Google Account gives you access to that Drive-backed workflow.

Account creation uses personal information. Keep your password out of screenshots and project notes.

  • Select the tab that matches your current account situation.

✔️ I have a Google Account

  • Choose the Google Account you will use for this project.

Your account is ready for the notebook sign-in during the next step.

ⓧ I need a Google Account

Google guides you through the required identity information. Choose a private password that you do not use in project content.

  • Open the official Google Account creation guide in Chrome.
  • Use the guide to reach the Google Account sign-in page.
  • Click Create account.
  • Choose the account type that fits your use.
  • Enter the requested identity details.
  • Create a private password.
  • Complete the remaining on-screen steps.

Your Google Account is now available for the notebook workspace.

Account Creation Getting Stuck?

  • Confirm that Chrome has an Internet connection.
  • Return to the official creation guide.
  • Repeat the step that stopped.

Keep passwords and personal details private when asking for help: Help me complete Google Account creation safely.

Your sign-in route is ready. The notebook can stay connected to your Google Drive workflow.

Define the calculator's purpose

Roughness average, or Ra, describes a surface-roughness measurement. Your calculator compares Ra before polishing with Ra after polishing for one metal sample.

  • Read the comparison one more time: pre-polishing roughness versus post-polishing roughness for one metal sample.

Before the final check, which two measurement stages should your sentence name?

Your sentence should name pre-polishing roughness and post-polishing roughness for one metal sample. You have now fixed the purpose of your first calculation.

Your browser and account are ready. Next, you will open Google Colab and prove that your notebook can run Python.

Open and Test Your Python Workspace

A roughness comparison needs a workspace that accepts Python instructions before it can run.

Google Colab is a hosted Jupyter Notebook service that runs in your browser. Its Google Drive storage lets you return to the notebook from another Internet-enabled device.

In this step, get ready to:
  • Open Google Colab in Google Chrome.
  • Create a new Python 3 notebook in Google Drive.
  • Run a code cell that proves the workspace is ready.
Open Google Colab in Chrome

Your Windows computer gives you more room for code entry. Signing in connects the notebook to your Google Account.

  • Press the Windows key to open the search bar.
  • Type Google Chrome into the search bar.
  • Press Enter to open Chrome.
  • Go to the Google Colab site.
  • Select your existing Google Account if Google shows account choices.
  • Complete the Google Account sign-in flow shown by Colab.

You'll see Colab connected to the Google Account you selected.

Create a new notebook

A notebook groups executable code into cells. Creating it while signed in keeps the file in your Google Drive.

  • Select File in Colab's top menu.
  • Select New.
  • Select New Python 3 notebook.

You'll see a new notebook with an empty code cell ready for input.

Your notebook now has a Drive-backed home that you can reach from either device.

Run the readiness check

A code cell runs Python instructions. Its output appears directly underneath.

  • Click the first empty code cell.
  • Enter the readiness instruction by copying the code below:
print("Surface metrology notebook ready")

What Does This Code Do?

  • The print() function asks Python to display a value in the cell output.
  • The quotation marks make the readiness message a string.

Before you run the cell, what message do you expect to appear beneath it?

  • Select the triangular play control to the left of the cell.
  • Check beneath the cell after execution finishes.

You'll see Surface metrology notebook ready beneath the cell.

You have your first successful Python cell. The notebook is ready to become your surface-roughness calculator.

Can't See the Readiness Message?

  • Check that the first cell contains the complete readiness instruction.
  • Select the triangular play control again.

Ask for help if the cell still does not display output: Help me check my Colab cell

Your browser-based Python workspace is ready. Next, you'll represent one polished-metal sample with named values.

Represent Your Metal Sample

Your Google Colab notebook has already run its first Python instruction. The readiness message confirms that your workspace can execute code.

Before Python can compare roughness measurements, each piece of sample data needs a meaningful name. A variable supplies that name through assignment.

Strings store text labels. Floating-point values store decimal measurements.

In this step, get ready to:
  • Assign each sample value to a meaningful variable.
  • Choose a suitable data type for each value.
  • Print the four raw values for inspection.
Understand the sample data model

The sample has two labels plus two Ra measurements. Their data types preserve how Python should treat each value.

How Does Assignment Work?

  • The = operator assigns the value on its right to the variable on its left.
  • The sample_id variable holds the specimen label as a string.
  • The process variable holds the polishing method as a string.
  • The ra_before_um variable holds the starting Ra measurement as a floating-point value.
  • The ra_after_um variable holds the final Ra measurement as a floating-point value.
  • The print() function displays the values stored in the variables.
Store and print the sample

One code cell can hold the complete sample record. Running that cell stores the values before displaying them for inspection.

  • Return to the code cell that contains print("Surface metrology notebook ready").
  • Click inside the code cell.
  • Select the readiness command.
  • Replace it with the sample code below:
sample_id = "METAL-001"
process = "Plasma Electrolytic Polishing"
ra_before_um = 1.84
ra_after_um = 0.42

print(sample_id, process, ra_before_um, ra_after_um)

What Does This Code Do?

  • Meaningful variable names connect each value to its engineering role.
  • Quoted values preserve the sample label plus the process name as text.
  • Numeric Ra values remain available for later arithmetic.
  • The print() function provides an immediate check of the stored values.

Before you run the cell, do you expect the output to include the variable names or only their stored values?

  • Run the cell by selecting the triangular control on its left.

You'll see METAL-001 Plasma Electrolytic Polishing 1.84 0.42 beneath the cell.

You've crossed the key threshold: your engineering data now exists as reusable Python values.

  • Confirm that the notebook indicates its latest changes are saved in Google Drive.

Output Missing or Different?

  • Check that every assignment appears above print() in the same code cell.
  • Check that each quoted value uses matching quotation marks.
  • Check that each variable name inside print() matches its assignment exactly.

Help me compare my sample cell with the expected output.

  • Double-check the completed notebook cell with the tabs below.

✔️ Awesome, I've got everything!

Your notebook cell matches the sample record. Keep the output visible for your checkpoint.

ⓧ I'd like to double check the full code

sample_id = "METAL-001"
process = "Plasma Electrolytic Polishing"
ra_before_um = 1.84
ra_after_um = 0.42

print(sample_id, process, ra_before_um, ra_after_um)

Your metal sample now has a clear Python representation. Next, you'll calculate how much the polishing process reduced its Ra value.

Calculate the Ra Change

Your Google Colab notebook already stores the roughness before polishing. It also stores the roughness after polishing.

Those raw measurements leave one engineering question unanswered: how much did the surface change?

Python arithmetic can calculate the absolute reduction in µm. Subtraction measures the drop from the starting value.

A ratio compares that drop with the starting measurement. Multiplication by 100 expresses the result as the project-defined percentage improvement.

In this step, get ready to:
  • Calculate the absolute Ra reduction in µm.
  • Calculate the relative Ra improvement as a percentage.
  • Print both unformatted values to inspect Python's result.
Understand absolute and relative change

An absolute reduction keeps the same measurement unit as the original values. It tells you how many µm the polishing process removed from the Ra measurement.

A relative improvement compares that reduction with the starting Ra value. This makes the change easier to compare across samples with different starting measurements.

  • Find ra_before_um = 1.84 in the existing sample cell.
  • Find ra_after_um = 0.42 directly below it.

How do the two results differ?

The absolute reduction subtracts ra_after_um from ra_before_um. Its result uses µm.

The percentage improvement divides that reduction by the starting value. This percentage is a derived comparison used for this project.

Calculate and verify the Ra change

A new code cell can reuse the measurement variables from the earlier cell. The new expressions assign each calculated result to a meaningful variable.

  • Switch back to the Google Colab notebook from earlier.
  • Add a code cell below the cell that prints the four raw values.
  • Copy the calculations plus the unformatted print statement by entering this code:
roughness_reduction_um = ra_before_um - ra_after_um
improvement_percent = (roughness_reduction_um / ra_before_um) * 100

print(roughness_reduction_um, improvement_percent)

What does this code do?

  • The roughness_reduction_um expression subtracts the final Ra measurement from the starting Ra measurement.
  • The improvement_percent expression divides the reduction by the starting measurement. Multiplication by 100 converts the ratio into a percentage.
  • The print() line sends both calculated values to the output with a space between them.

✔️ Awesome, I've got everything!

Your notebook contains the original sample values plus both calculated results.

ⓧ I'd like to double check the full code

  • Compare your notebook with this complete code:
sample_id = "METAL-001"
process = "Plasma Electrolytic Polishing"
ra_before_um = 1.84
ra_after_um = 0.42

print(sample_id, process, ra_before_um, ra_after_um)

roughness_reduction_um = ra_before_um - ra_after_um
improvement_percent = (roughness_reduction_um / ra_before_um) * 100

print(roughness_reduction_um, improvement_percent)

How to use this reference

  • The first section preserves the sample details plus the original raw-value output.
  • The second section calculates the Ra reduction plus the percentage improvement.
  • The final line prints both calculated values without decimal formatting.
  • Before you run the calculation cell, predict whether the reduction in µm or the percentage improvement will be numerically larger.
  • Run the calculation cell with the triangular button on its left.

You'll see an Ra reduction close to 1.42 followed by a percentage close to 77.17.

The extra decimal detail is expected because these values are still unformatted. You will control that precision when you build the engineering report.

Results missing or different?

  • Run the earlier sample cell if Python reports that a variable is missing.
  • Compare every variable name with the reference code if either result differs.
  • Check that the percentage expression divides by ra_before_um before multiplying by 100.

Help me debug my Ra reduction and percentage calculations in Google Colab.

You have turned two raw Ra measurements into a clear reduction plus a relative improvement. Next, you will format those results as a labelled engineering report.

Create an Engineering Report

Your Google Colab notebook now calculates the change in Ra for the polished-metal sample. The raw output proves the arithmetic works.

An engineering report identifies every value using a clear label. In this step, you will turn those values into a unit-aware Surface Roughness Report with controlled precision.

In this step, get ready to:
  • Build a labelled report from the existing variables.
  • Control the displayed decimal precision with formatted string literals.
  • Run the full notebook to verify the final results.
Format the engineering report

A formatted string literal places a variable inside {} within a string. A format specifier such as .2f or .1f controls how many decimal places appear.

  • Use the notebook toolbar's code-cell control to add a new cell beneath print(roughness_reduction_um, improvement_percent).
  • Build the labelled report by pasting this code into the new cell:
print("Surface Roughness Report")
print(f"Sample: {sample_id}")
print(f"Process: {process}")
print(f"Ra before polishing: {ra_before_um:.2f} µm")
print(f"Ra after polishing: {ra_after_um:.2f} µm")
print(f"Absolute Ra reduction: {roughness_reduction_um:.2f} µm")
print(f"Roughness improvement: {improvement_percent:.1f}%")

How does the formatting work?

  • The f prefix marks each line as a formatted string literal.
  • Expressions inside {} insert the current variable values.
  • The .2f specifier displays each Ra value with two decimal places.
  • The .1f specifier displays the improvement percentage with one decimal place.
  • The surrounding text supplies labels plus measurement units.
  • Run the new report cell using the triangular run icon beside it.

You'll see a report headed Surface Roughness Report. The report includes Absolute Ra reduction: 1.42 µm.

It also includes Roughness improvement: 77.2%. Good work. Your labelled report now presents the Ra reduction with its unit.

Report Cell Not Running?

Check that every opening quote has a matching closing quote. Confirm that each variable name matches the earlier cells exactly.

Compare the braces plus format specifiers with the reference below. A missing brace prevents the formatted line from running.

Help me debug my formatted report cell.

✔️ Awesome, I've got everything!

Your completed report code is ready in the notebook.

ⓧ I'd like to double check the full code

  • Compare your notebook with this cumulative version:
sample_id = "METAL-001"
process = "Plasma Electrolytic Polishing"
ra_before_um = 1.84
ra_after_um = 0.42

print(sample_id, process, ra_before_um, ra_after_um)

roughness_reduction_um = ra_before_um - ra_after_um
improvement_percent = (roughness_reduction_um / ra_before_um) * 100

print(roughness_reduction_um, improvement_percent)

print("Surface Roughness Report")
print(f"Sample: {sample_id}")
print(f"Process: {process}")
print(f"Ra before polishing: {ra_before_um:.2f} µm")
print(f"Ra after polishing: {ra_after_um:.2f} µm")
print(f"Absolute Ra reduction: {roughness_reduction_um:.2f} µm")
print(f"Roughness improvement: {improvement_percent:.1f}%")
Run the complete notebook

A top-to-bottom run confirms that the report uses the values calculated by the earlier cells. It also lets you compare the raw floating-point output with the formatted result.

Before you run the full notebook, predict whether the final percentage will keep the raw output's extra precision.

  • Run each code cell from top to bottom using the triangular run icon beside each cell.
  • Scroll to the output beneath the final report cell.
  • Compare the report's percentage with the raw percentage printed above it.

You'll see the raw results first. Beneath them, you'll see the labelled Surface Roughness Report.

The final report includes Absolute Ra reduction: 1.42 µm. It also includes Roughness improvement: 77.2%.

Why Did the Percentage Change?

Formatting changes how a value appears. The value stored in improvement_percent stays close to 77.17.

The :.1f specifier rounds the displayed percentage to one decimal place. This gives the report consistent precision.

That's the full calculator complete. Your notebook now turns polished-metal measurements into a report with controlled precision.

Secret mission

Extend the Calculator to Rq

Extend your polished-metal report with Rq measurements. You will reuse the Ra calculation pattern to prove your notebook can analyse a second surface-roughness parameter.

Clean Up Your Resources

Clean Up Your Resources

Google Colab is free of charge to use. Choose Keep, Pause, or Delete for your Google Drive-backed notebook.

Resources you used:

  • The surface_roughness_day1.ipynb notebook containing your validated Ra and Rq calculations.

Keep everything running

No action is needed. This option keeps your calculator available for future experiments.

  • Leave surface_roughness_day1.ipynb in Google Drive.
  • Reopen the notebook from Google Drive when you want to continue.
  • Run all cells to regenerate the validated Ra and Rq report.

Pause - I'll come back to this later

There is no server or local Python process to stop. A downloaded notebook gives you a backup before you close the browser tab.

  • Return to the Colab notebook from earlier.
  • Use the File menu to download the notebook in .ipynb format.
  • Confirm surface_roughness_day1.ipynb appears in your Downloads folder.
  • Close the Colab browser tab.

Delete - I don't want to use this again

Deleting the notebook removes your calculator from Google Drive. A downloaded backup preserves a copy if you change your mind.

  • Download a backup from Colab's File menu if you may want the calculator later.
  • Find surface_roughness_day1.ipynb in Google Drive using Google Chrome.
  • Use the notebook's file actions menu to delete it from Google Drive.
  • Open Google Drive's deleted-files area.
  • Use the permanent-delete control for surface_roughness_day1.ipynb.
  • Confirm the notebook no longer appears in the deleted-files area.

Nice Work!

Nice Work!

Great work! Your Google Colab notebook now turns polished-metal Ra and Rq measurements into a labelled surface roughness report.

You've learned how to:

  • Represent polished-metal sample data with Python variables that store strings and floating-point values.
  • Calculate the absolute roughness reduction from before-and-after Ra measurements. Derive a percentage improvement from the starting value.
  • Use print() to turn raw numbers into a labelled report. Apply formatted string literals to insert each value. Control the displayed precision with decimal formatting while keeping the µm and % units visible.
  • Secret Mission: Extended the calculator to Rq. Confirmed an absolute reduction of 1.75 µm and an improvement of 76.1%.

Ready to quiz yourself?