Coding Practice

Sharing the programming exercises I practice while learning to code.

Beginner · Python ·

Python Coding Exercise #32: Age of Maturity

A beginner Python exercise on if and else — decide whether someone is of age using 18 as the limit, and see why the boundary value 18 is the number to test.

Beginner · Python ·

Python Coding Exercise #31: Typecasting

A beginner Python exercise on type conversion — use int() to split a decimal number into its integer part and decimal part, and see why the decimal part can print with extra digits.

Beginner · Python ·

Python Coding Exercise #30: Number of Characters

A beginner Python exercise on the len() function and if statements — count the characters in a word and print the count only when the word has more than one character.

Beginner · Python ·

Python Coding Exercise #29: Fix the Syntax

A beginner Python debugging exercise — find and fix ten syntax, indentation and type errors in a short program, and learn how to read Python's error messages.

Beginner · Python ·

Python Coding Exercise #28: Solving a Quadratic Equation

A beginner Python exercise that turns the quadratic formula into code — read a, b and c, calculate the discriminant, and use sqrt() to find the two roots, with attention to brackets and order of operations.

Beginner · Python ·

Python Coding Exercise #27: Hypotenuse of a Right-Angled Triangle

A beginner Python exercise on the math module — use Pythagoras' theorem and sqrt() to find the hypotenuse of a right-angled triangle, read decimal sides with float(), and format the answer to two decimal places.

Beginner · Python ·

Python Coding Exercise #26: Random Number Between Two Numbers

A beginner Python exercise on the random module — generate a random whole number between two numbers with randint(), and learn that both ends are included and that the numbers must be in order.

Beginner · Python ·

Python Coding Exercise #25: Greatest Common Divisor

A beginner Python exercise on the math module — find the greatest common divisor of two numbers with math.gcd(), and understand what a GCD is and how Euclid's method finds it.

Beginner · Python ·

Python Coding Exercise #24: Binary, Octal and Hexadecimal

A beginner Python exercise on number systems — convert a decimal integer to binary, octal and hexadecimal with the built-in functions bin(), oct() and hex(), and learn what the 0b, 0o and 0x prefixes mean.

Beginner · Python ·

Python Coding Exercise #23: Slicing and the min() and max() Functions

Two short beginner Python exercises — use string slicing to print the last three digits of a phone number, and use the built-in min() and max() functions to find the smallest and largest of four numbers.