Python Practice Exercise
62 parts, newest first.
Python Coding Exercise #62: Substrings, Parts 1 and 2
Two beginner Python exercises on slicing in a loop — print all the substrings of a word that start with its first character, then all the substrings that end with its last character, using for loops and while loops.
Python Coding Exercise #61: A Framed Word
A beginner Python exercise on string methods and string multiplication — print a word in the centre of a 30-character frame of asterisks, using center() and a manual version with len() and floor division.
Python Coding Exercise #60: Right-Aligned
A beginner Python exercise on string methods — print a string so that exactly 20 characters are shown, filling the start with asterisks, using rjust() and a manual version with len() and string multiplication.
Python Coding Exercise #59: Underlining
A beginner Python exercise on loops, len() and string multiplication — keep asking for strings, print each one underlined with dashes of the same length, and stop when the user presses Enter on an empty line.
Python Coding Exercise #58: A Line and a Rectangle of Hashes
Two beginner Python exercises on repeating output — print a line of hash characters of a chosen width, then repeat that line to draw a rectangle, with a for loop and a while loop compared.
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.
Python Coding Exercise #56: End to Beginning
A beginner Python exercise on string indexing and while loops — print a string in reverse, one character per line, by counting an index down from -1 using negative indexes.
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.
Python Coding Exercise #54: String Multiplied
A beginner Python exercise on string repetition — ask for a string and an amount, then print the string that many times on one line using the * operator.
Python Coding Exercise #53: The Sum of Consecutive Numbers
Two beginner Python exercises on a while loop that adds 1, 2, 3 and so on until the total reaches a limit, then builds the calculation as text to print it too.