PyPro: challenge 1#
This challenge is due on Sunday 29th September 2024 at 8pm.#
These exercises provide a wide range of challenges that test your understanding of Python's core concepts, such as control structures, data types, string manipulations, list comprehensions, and higher-order functions.
Basic Tasks#
Create a function
find_max()
that accepts two numeric inputs and returns the greater value. Avoid using the built-inmax()
function.Develop a function
find_max_of_three()
to find the maximum among three given numbers.Write a function to manually calculate the length of a given list or string without using
len()
.Implement a function that checks if a given character is a vowel (a, e, i, o, u).
Write a function
encode()
that converts a string into “rövarspråket” (robber’s language) by doubling consonants and placing “o” in between, e.g., “hello” -> “hohelollolo”.Create
sum_elements()
andproduct_elements()
functions to sum and multiply all elements in a list, respectively.Define a function
reverse_string()
to reverse the characters in a given string.Implement
check_palindrome()
to verify if a string reads the same forwards and backwards, i.e. is a palindrome.Develop a function
check_membership()
to determine if a value exists within a list.Write
check_overlap()
to identify if two lists share any elements.Implement
repeat_char()
that generates a string with a specified character repeatedn
times.Create a function
print_histogram()
that takes a list of integers and prints a corresponding histogram.Write
find_max_in_list()
to identify the largest number in a list of arbitrary length.Create a program that maps each word in a list to its length.
Implement
longest_word()
to find the longest word in a list.Develop
filter_words()
to return words longer than a specified length from a list.Enhance the palindrome recognizer to handle phrases, ignoring spaces, punctuation, and case.
Implement a function that checks if a given sentence is a pangram.
Write a function that generates verses for the “99 Bottles of Beer” song.
Create a translation function using a small dictionary to translate English words into French/.
Develop
char_frequency()
to build a dictionary of character frequencies in a string.Implement a Caesar cipher encoder/decoder using a shift of 13 (ROT-13).
Create
fix_spaces()
to correct multiple spaces and missing spaces after periods in a text.Write
convert_to_third_person()
to transform verbs into their third person singular form.Implement
make_ing_form()
to convert verbs into their present participle form using heuristic rules.
Higher-Order Functions and List Comprehensions#
Use
reduce()
to writemax_in_list()
that returns the largest number in a list.Write a program that maps words to their lengths using a for-loop,
map()
, and list comprehensions.Implement
find_longest_word()
using only higher-order functions.Use
filter()
to writefilter_long_words()
that filters words longer thann
.Create
translate_with_map()
to translate English words to French usingmap()
.Re-implement the higher-order functions
map()
,filter()
, andreduce()
from scratch.
Simple Tasks with I/O#
Write a palindrome recognizer that reads lines from a file and prints only the palindromes.
Implement a semordnilap recognizer that finds word pairs from a file where each word is the reverse of the other.
Create
char_frequency_table()
to display a sorted character frequency table from a file.Write a function
speak_ICAO()
that translates text into the ICAO phonetic alphabet.Implement
find_hapaxes()
to identify words that occur only once in a text file.Write a program that numbers each line in a text file.
Calculate the average word length in a text file.
Implement a number-guessing game where the user guesses a number between 1 and 20.
Write a program that presents an anagram of a randomly chosen word and allows the user to guess the original.
Create a Lingo game where players guess a hidden word, receiving clues about correct and misplaced characters.
Advanced Tasks#
Develop a sentence splitter that separates a text into sentences based on various heuristics.
Write a program to find the largest group of anagrams in a given word list.
Generate a string of balanced brackets and verify if it is balanced.
Create a word chain game where each word starts with the last letter of the previous one, using a list of Pokemon names.