Tagged: strings
Everything tagged "strings", newest first.
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.
Python Coding Exercise #49: Story
A beginner Python exercise on building a string inside a loop — collect words from the user until they type "end" or repeat the previous word, and learn how to remember the previous value.
Python Coding Exercise #46: Repeat Password
A beginner Python exercise on loops and input — ask for a password once, then keep asking the user to repeat it until it matches, and learn which lines belong inside the loop and which outside.
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.
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.
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.
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 #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 #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.
Python Coding Exercise #20: What to Wear Tomorrow
A beginner Python exercise on comparison conditions — turn "over 20, 10 or 5 degrees" into the right if statements, learn how to pick between <, <=, > and >=, and practise with boundary values.