All assignment work will be done in the included template files on GitHub as per usual. Please do not forget to fill out the metadata at the top of each template! At the very least fill out if you worked alongside anyone to give them proper credit.
Accept AssignmentProblem 1
Here your goal is to write a function named draw_complex_pyramid
that takes three parameters:
height
: The height of the pyramidsymbol
: The character used to build the pyramid (default:*
)style
: Indicating the pattern (e.g., ‘solid’, ‘hollow’, ‘alternating’). See each pattern below.
Example outputs for different styles assuming the value for height
is 8:
Solid Pattern
:
>>> draw_console_pyramid(8, '*', solid)
*
***
*****
*******
*********
***********
*************
***************
Hollow Pattern
:
>>> draw_console_pyramid(8, '*', hollow)
*
* *
* *
* *
* *
* *
* *
***************
Alternating Pattern
:
>>> draw_console_pyramid(8, '*', alternate)
*
@@@
*****
@@@@@@@
*********
@@@@@@@@@@@
*************
@@@@@@@@@@@@@@@
Requirements:
- The function must validate input parameters:
- Height must be a positive integer
- Symbol must be a single character
- Style must be one of the predefined patterns
- Each row should be properly centered
- The bottom row should start at the left margin
- Implement error handling for invalid inputs
- The width of each row should still increase by 2 as you move downward
Problem 2
Part A
As you will discover next week, implementing the Wordle project requires you to take account of the possibility that a word might contain more than one instance of the same letter. In preparation of that, your task here is to write a predicate function called contains_repeated_letters(word)
which returns True
if any of the characters in the word appear more than once, not necessarily consecutively. Thus,
"single") contains_repeated_letters(
should return False
, as no letter ever shows up twice. Conversely,
"repeating") contains_repeated_letters(
should return True
, as the letter "e"
shows up twice. Test your function against more words to ensure that it is working properly!
Part B
Now use contains_repeated_letters
together with the english.py
library to write a function called longest_no_repeats
that finds and returns the longest word in the English dictionary that contains no repeated letters.
Problem 3
Many people in English-speaking countries have played the Pig Latin game at some point in their lives. There are other invented “languages” in which words are created using some simple transformation of English. One such language is called Obenglobish, in which words are created by adding the letters ob before the vowels (a, e, i, o and u) in an English word. For example, under this rule, the word english gets the letters ob added before the e and the i, to form obenglobish, which is how the language got its name.
In official Obenglobish, the ob characters are only added before vowels that are pronounced, which means that a word like game would become gobame rather than gobamobe since the final e is silent. While it is impossible to implement this rule perfectly, you can do a pretty good job by adopting the rule that ob should be added before every vowel in the word except when:
- the vowel follows another vowel
- the vowel is an e occurring at the end of a word
Write a function to_obenglobish
that takes an English word as an argument and returns its Obenglobish equivalent, using the translation rules above. For example, your function should be able to output something similar to below:
>>> print(to_obenglobish("english"))
obenglobish>>> print(to_obenglobish("gooiest"))
gobooiest>>> print(to_obenglobish("amaze"))
obamobaze>>> print(to_obenglobish("rot"))
robot
Don’t forget about decomposition! I found it very useful on this problem to write predicate functions to take care of checking the above special conditions.