Tagged: conditionals

Everything tagged "conditionals", newest first.

Coding Practice ·

Python Coding Exercise #57: Second and Second to Last Characters

A beginner Python exercise on string indexes and short-circuit conditions — compare the second and second to last characters of a string, and learn why a very short string needs a length check first.

Coding Practice ·

Python Coding Exercise #55: The Longer String

A beginner Python exercise on len() and if, elif and else — compare the lengths of two strings and print whichever is longer, or a message when they are equally long.

Coding Practice ·

Python Coding Exercise #42: Gift Tax Calculator

A beginner Python exercise on if, elif and else with several ranges — calculate gift tax from a table of brackets, and learn to turn a complicated table into a simple reference table before writing any code.

Coding Practice ·

Python Coding Exercise #41: Alphabetically in the Middle

A beginner Python exercise on comparing strings and chained comparisons — find which of three letters would be in the middle in alphabetical order, and compare a chained-comparison solution with a nested if solution.

Coding Practice ·

Python Coding Exercise #40: Leap Year

A beginner Python exercise on if, elif and else with the remainder operator — decide whether a year is a leap year, handle the century-year exception, and compare a flat chain of conditions with a nested if.

Coding Practice ·

Python Coding Exercise #39: FizzBuzz

A beginner Python exercise on the remainder operator and the and operator — print Fizz, Buzz or FizzBuzz depending on whether a number is divisible by 3, 5 or both, and see why the order of the conditions matters.

Coding Practice ·

Python Coding Exercise #38: Grades and Points

A beginner Python exercise on if, elif and else with ranges — turn a table of point boundaries into a grade, handle impossible values, and see two ways to write the conditions.

Coding Practice ·

Python Coding Exercise #37: Nephews

A beginner Python exercise on the or operator — recognise a name that matches any one of several options, avoid the classic mistake of writing or "Dewey", and meet the shorter in operator.

Coding Practice ·

Python Coding Exercise #36: Age Check

A beginner Python exercise on if, elif and else with three outcomes — respond to an age that is normal, too young, or impossible — and learn why the order of the conditions matters.

Coding Practice ·

Python Coding Exercise #35: Alphabetically Last

A beginner Python exercise on comparing strings — find which of two words comes last in alphabetical order, and learn how Python compares text, including the effect of uppercase letters.

All tags