Tagged: python
Everything tagged "python", newest first.
Python Coding Exercise #34: The Elder
A beginner Python exercise on if, elif and else — read the names and ages of two people, print the name of the elder, and avoid the mistakes of comparing the wrong variables or comparing ages as text.
Python Coding Exercise #33: Greater Than or Equal To
A beginner Python exercise on if, elif and else — compare two numbers, print the greater one, and handle the case where they are equal.
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.
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.
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.
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.
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.
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.
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.
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.