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#

  1. Create a function find_max() that accepts two numeric inputs and returns the greater value. Avoid using the built-in max() function.

  2. Develop a function find_max_of_three() to find the maximum among three given numbers.

  3. Write a function to manually calculate the length of a given list or string without using len().

  4. Implement a function that checks if a given character is a vowel (a, e, i, o, u).

  5. 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”.

  6. Create sum_elements() and product_elements() functions to sum and multiply all elements in a list, respectively.

  7. Define a function reverse_string() to reverse the characters in a given string.

  8. Implement check_palindrome() to verify if a string reads the same forwards and backwards, i.e. is a palindrome.

  9. Develop a function check_membership() to determine if a value exists within a list.

  10. Write check_overlap() to identify if two lists share any elements.

  11. Implement repeat_char() that generates a string with a specified character repeated n times.

  12. Create a function print_histogram() that takes a list of integers and prints a corresponding histogram.

  13. Write find_max_in_list() to identify the largest number in a list of arbitrary length.

  14. Create a program that maps each word in a list to its length.

  15. Implement longest_word() to find the longest word in a list.

  16. Develop filter_words() to return words longer than a specified length from a list.

  17. Enhance the palindrome recognizer to handle phrases, ignoring spaces, punctuation, and case.

  18. Implement a function that checks if a given sentence is a pangram.

  19. Write a function that generates verses for the “99 Bottles of Beer” song.

  20. Create a translation function using a small dictionary to translate English words into French/.

  21. Develop char_frequency() to build a dictionary of character frequencies in a string.

  22. Implement a Caesar cipher encoder/decoder using a shift of 13 (ROT-13).

  23. Create fix_spaces() to correct multiple spaces and missing spaces after periods in a text.

  24. Write convert_to_third_person() to transform verbs into their third person singular form.

  25. Implement make_ing_form() to convert verbs into their present participle form using heuristic rules.

Higher-Order Functions and List Comprehensions#

  1. Use reduce() to write max_in_list() that returns the largest number in a list.

  2. Write a program that maps words to their lengths using a for-loop, map(), and list comprehensions.

  3. Implement find_longest_word() using only higher-order functions.

  4. Use filter() to write filter_long_words() that filters words longer than n.

  5. Create translate_with_map() to translate English words to French using map().

  6. Re-implement the higher-order functions map(), filter(), and reduce() from scratch.

Simple Tasks with I/O#

  1. Write a palindrome recognizer that reads lines from a file and prints only the palindromes.

  2. Implement a semordnilap recognizer that finds word pairs from a file where each word is the reverse of the other.

  3. Create char_frequency_table() to display a sorted character frequency table from a file.

  4. Write a function speak_ICAO() that translates text into the ICAO phonetic alphabet.

  5. Implement find_hapaxes() to identify words that occur only once in a text file.

  6. Write a program that numbers each line in a text file.

  7. Calculate the average word length in a text file.

  8. Implement a number-guessing game where the user guesses a number between 1 and 20.

  9. Write a program that presents an anagram of a randomly chosen word and allows the user to guess the original.

  10. Create a Lingo game where players guess a hidden word, receiving clues about correct and misplaced characters.

Advanced Tasks#

  1. Develop a sentence splitter that separates a text into sentences based on various heuristics.

  2. Write a program to find the largest group of anagrams in a given word list.

  3. Generate a string of balanced brackets and verify if it is balanced.

  4. Create a word chain game where each word starts with the last letter of the previous one, using a list of Pokemon names.