CP1 / COURSE HOME

CP1 · 14 weeks · Dr. Arif Solmaz

Computer Programming I

Learn Python through small engineering problems. Open a week, follow the examples, then try the notebook when the lesson asks you to.

Mechatronics engineering · Follow class announcements for dates

Weekly lessons

WeekTopicLesson
01Describe a wheel’s travelColab Setup, Variables & Data TypesOpen →
02Report a measurement clearlyOperators, F-Strings & Type ConversionOpen →
03Turn an operating rule into a decisionConditionals & Decision MakingOpen →
04Observe a signal over timefor Loops & range -- RepetitionOpen →
05Give a search a stopping rulewhile Loops, break & continueOpen →
06Choose a useful summaryProblem-Solving PatternsOpen →
07Keep the original observationsLists FundamentalsOpen →
08Find a reading in a grid2D Lists & Nested LoopsOpen →
09Read a device messageString ProcessingOpen →
10Convert a sensor reading into a forceFunctions — BasicsOpen →
11Use the same function with two sensorsScope & Mini-LibraryOpen →
12Separate a missing reading from zeroError HandlingOpen →
13Save a report someone can checkFile I/O & CSVOpen →
14Bring the sensor report togetherMini Project — Sensor Log SummaryOpen →
Course information & resources

Weekly notebooks are private practice. The midterm and final each contribute 50%.

Notebook & solution library
Week 01 · Colab Setup, Variables & Data Types

Week 01 · Describe and decide

Describe a wheel’s travel

Give one physical quantity a name, a value and a unit.

Explain how you obtained the distance, where the millimetre-to-metre conversion happens, and why wheel slip could change the actual travel.

Start Week 01 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: Colab Setup, Variables & Data Types. 8 core / 7 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Personal Info (Easy)Core
EX02Rectangle Calculator (Easy)Core
EX03Temperature Converter (Medium)Core
EX04Speed Calculator (Easy)Core
EX05Compound Interest (Medium)Core
EX06BMI Calculator (Medium)Core
EX07All Operations (Medium)Core
EX08Circle Properties (Medium)Core
EX09Ohm's Law (Easy)Optional
EX10Power Calculation (Easy)Optional
EX11Kinetic Energy (Medium)Optional
EX12Pythagorean Theorem (Medium)Optional
EX13Minutes Converter (Medium)Optional
EX14String Operations (Easy)Optional
EX15Engineering Report (Challenge)Optional
Week 02 · Operators, F-Strings & Type Conversion

Week 02 · Describe and decide

Report a measurement clearly

Turn a numeric result into a useful message.

Show a readable measurement message without letting display rounding change the inspection result.

Start Week 02 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: Operators, F-Strings & Type Conversion. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Operator Predictions (Easy)Core
EX02Type Conversion Traps (Easy)Core
EX03Seconds Breakdown (Medium)Core
EX04Formatted Receipt (Medium)Core
EX05Compound Interest with Input (Medium)Core
EX06Currency Converter (Medium)Core
EX07Temperature Table (Medium)Core
EX08String Explorer (Easy)Core
EX09Number Formatting (Medium)Optional
EX10Grade Average (Medium)Optional
EX11Electrical Calculator (Medium)Optional
EX12BMI with Categories (Challenge)Optional
Week 03 · Conditionals & Decision Making

Week 03 · Describe and decide

Turn an operating rule into a decision

Make every combination of conditions have a clear outcome.

Explain an ENABLE or DENY result from the rule, including the exact threshold. This exercise models a decision; it does not implement a hardware interlock.

Start Week 03 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: Conditionals & Decision Making. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Positive, Negative, or Zero (Easy)Core
EX02Even or Odd (Easy)Core
EX03Grade Calculator (Medium)Core
EX04Leap Year (Medium)Core
EX05Ticket Price (Medium)Core
EX06Triangle Validator (Medium)Core
EX07Maximum of Three (Medium)Core
EX08Season Classifier (Easy)Core
EX09BMI Classifier (Medium)Optional
EX10Quadrant Finder (Medium)Optional
EX11Vowel or Consonant (Easy)Optional
EX12Simple Calculator (Challenge)Optional
Week 04 · for Loops & range -- Repetition

Week 04 · Describe and decide

Observe a signal over time

Choose when to look, then explain what you actually observed.

List the times your program inspected and explain why an empty alarm log does not establish that nothing happened between samples.

Start Week 04 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: for Loops & range -- Repetition. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Print 1 to 20 (Easy)Core
EX02Sum 1 to N (Easy)Core
EX03Factorial (Medium)Core
EX04Multiplication Table (Medium)Core
EX05Count Even Numbers (Medium)Core
EX06Sum of Odd Numbers (Medium)Core
EX07Star Pattern — Right Triangle (Medium)Core
EX08Star Pattern — Inverted (Medium)Core
EX09Power Calculator (Medium)Optional
EX10Fibonacci Sequence (Medium)Optional
EX11Find All Divisors (Medium)Optional
EX12Number Pyramid (Challenge)Optional
Week 05 · while Loops, break & continue

Week 05 · Describe and decide

Give a search a stopping rule

Repeat an action until an outcome is known.

Trace the search without an extra move, including when the switch activates on the fifth move.

Start Week 05 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: while Loops, break & continue. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Countdown (Easy)Core
EX02Sum Until Zero (Easy)Core
EX03Guess the Number (Medium)Core
EX04Password Checker (Medium)Core
EX05Digit Counter (Medium)Core
EX06Digit Sum (Medium)Core
EX07Reverse Number (Medium)Core
EX08Collatz Conjecture (Medium)Core
EX09Find First Divisor (Medium)Optional
EX10Skip Multiples (Medium)Optional
EX11Menu System (Challenge)Optional
EX12Prime Checker (Challenge)Optional
Week 06 · Problem-Solving Patterns

Week 06 · Organise observations

Choose a useful summary

Decide what the report needs before calculating a statistic.

Choose and justify a summary that reveals the 8 A sample, and describe what it cannot tell us about unsampled moments.

Start Week 06 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: Problem-Solving Patterns. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Sum of Multiples (Easy)Core
EX02Count Positive (Easy)Core
EX03Find Maximum (Medium)Core
EX04Find Minimum (Medium)Core
EX05Average Calculator (Medium)Core
EX06Count Above Average (Medium)Core
EX07Second Largest (Medium)Core
EX08Perfect Numbers (Medium)Core
EX09GCD Calculator (Medium)Optional
EX10Temperature Summary (Medium)Optional
EX11Frequency Counter (Medium)Optional
EX12Sensor Data Report (Challenge)Optional
Week 07 · Lists Fundamentals

Week 07 · Organise observations

Keep the original observations

Store a sequence so you can ask more than one question of it.

Find a maximum while preserving enough information to say when it occurred and what followed it.

Start Week 07 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: Lists Fundamentals. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Create and Print (Easy)Core
EX02Sum a List (Easy)Core
EX03Find Maximum (Medium)Core
EX04Reverse a List (Medium)Core
EX05Count Occurrences (Medium)Core
EX06Remove Duplicates (Medium)Core
EX07Even Numbers Only (Medium)Core
EX08List Statistics (Medium)Core
EX09Merge Two Lists (Medium)Optional
EX10Swap First and Last (Easy)Optional
EX11Rotate List (Medium)Optional
EX12Grade Summary (Challenge)Optional
Week 08 · 2D Lists & Nested Loops

Week 08 · Organise observations

Find a reading in a grid

Keep the location attached to the value.

Report the peak as a temperature and a row–column pair. Explain why those indices are not physical distances.

Start Week 08 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: 2D Lists & Nested Loops. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Create a 3x3 Matrix (Easy)Core
EX02Print Matrix Formatted (Easy)Core
EX03Row Sums (Medium)Core
EX04Column Sums (Medium)Core
EX05Find Maximum Element (Medium)Core
EX06Diagonal Sum (Medium)Core
EX07Transpose (Medium)Core
EX08Student Grades Table (Medium)Core
EX09Matrix Addition (Medium)Optional
EX10Flatten 2D to 1D (Medium)Optional
EX11Temperature Grid (Challenge)Optional
EX12Multiplication Table (Challenge)Optional
Week 09 · String Processing

Week 09 · Organise observations

Read a device message

Agree on the record format before extracting its value.

Explain which field is the value and which fields give it context, and reject an incomplete or unsupported message for a stated reason.

Start Week 09 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: String Processing. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Word Counter (Easy)Core
EX02Vowel Counter (Easy)Core
EX03Reverse a String (Medium)Core
EX04Palindrome Checker (Medium)Core
EX05Capitalize Words (Medium)Core
EX06CSV Line Parser (Medium)Core
EX07Character Frequency (Medium)Core
EX08Acronym Generator (Medium)Core
EX09Replace Digits (Medium)Optional
EX10Email Validator (Medium)Optional
EX11Log Parser (Challenge)Optional
EX12Caesar Cipher (Challenge)Optional
Week 10 · Functions — Basics

Week 10 · Build a checkable report

Convert a sensor reading into a force

Give a reusable calculation a clear input and output.

Explain the function’s input, output and calibrated range, and distinguish a calculated extrapolation from a supported measurement.

Start Week 10 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: Functions — Basics. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Greet Function (Easy)Core
EX02Area of Circle (Easy)Core
EX03Celsius to Fahrenheit (Easy)Core
EX04Max of Two (Medium)Core
EX05Is Even (Medium)Core
EX06Factorial Function (Medium)Core
EX07Is Prime (Medium)Core
EX08Power Function (Medium)Core
EX09Count Vowels Function (Medium)Optional
EX10List Average (Medium)Optional
EX11BMI Calculator Function (Medium)Optional
EX12Mini Calculator (Challenge)Optional
Week 11 · Scope & Mini-Library

Week 11 · Build a checkable report

Use the same function with two sensors

Make the information a calculation depends on visible.

Process A, then B, then A again and explain why A’s two results agree.

Start Week 11 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: Scope & Mini-Library. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Scope Prediction (Easy)Core
EX02Fix the Scope Bug (Easy)Core
EX03Temperature Library (Medium)Core
EX04Math Helper Library (Medium)Core
EX05String Helper Library (Medium)Core
EX06Statistics Library (Medium)Core
EX07Geometry Library (Medium)Core
EX08Refactor — Inline to Functions (Medium)Core
EX09Validator Library (Medium)Optional
EX10Composition (Medium)Optional
EX11Grade Report Generator (Challenge)Optional
EX12Physics Calculator (Challenge)Optional
Week 12 · Error Handling

Week 12 · Build a checkable report

Separate a missing reading from zero

Keep a failed measurement from becoming believable data.

Keep valid zero and negative temperatures while distinguishing them from records that could not be measured or interpreted.

Start Week 12 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: Error Handling. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Catch Division Error (Easy)Core
EX02Safe Integer Input (Easy)Core
EX03Safe List Access (Medium)Core
EX04Calculator with Error Handling (Medium)Core
EX05Safe Division Function (Medium)Core
EX06Validate and Convert (Medium)Core
EX07Robust Average (Medium)Core
EX08Temperature Converter with Full Validation (Medium)Core
EX09Grade Entry System (Medium)Optional
EX10Multiple Error Types (Medium)Optional
EX11Retry Pattern (Challenge)Optional
EX12Robust Data Processor (Challenge)Optional
Week 13 · File I/O & CSV

Week 13 · Build a checkable report

Save a report someone can check

Preserve the raw input and make the output reproducible.

Follow one accepted and one rejected record from the raw file to the saved outputs without overwriting the original evidence.

Start Week 13 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: File I/O & CSV. 8 core / 4 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Create and Read (Easy)Core
EX02Count Lines (Easy)Core
EX03Write a List (Medium)Core
EX04Read Numbers (Medium)Core
EX05Copy File (Medium)Core
EX06Search in File (Medium)Core
EX07CSV Reader (Medium)Core
EX08CSV Writer (Medium)Core
EX09Grade Report from CSV (Medium)Optional
EX10Temperature Log (Medium)Optional
EX11Append to Log (Medium)Optional
EX12Data Cleaner (Challenge)Optional
Week 14 · Mini Project — Sensor Log Summary

Week 14 · Build a checkable report

Bring the sensor report together

Connect the steps and explain the result to another engineer.

Walk another person through the cleaned CSV, summary and one handled fault. Explain one limitation of the result using evidence from your own run.

Start Week 14 →

Read the lesson and its examples on one page. Continue in Colab when you are ready to try them.

Notebook, solutions & practice reference

Python tools: Mini Project — Sensor Log Summary. 10 core / 2 optional exercises. Weekly notebooks are private practice.

Lesson in Colab Download notebook Worked solutions in Colab Download solutions
Exercise list
IDNotebook exerciseRole
EX01Create and inspect the sample dataset (provided setup)Core
EX02Read and Parse the CSVCore
EX03Validate a Single RowCore
EX04Clean the DataCore
EX05Stats for One SensorCore
EX06Stats for All SensorsCore
EX07Generate Summary ReportCore
EX08Write Clean CSVCore
EX09Write Report to FileCore
EX10The Complete ProgramCore
EX11BONUS — Date/Time Filtering (Challenge)Optional
EX12BONUS — Sensor Comparison (Challenge)Optional