You are only allowed to access this course webpage, the Python documentation, Graphics documentation, and Sprite webpages. You are not allowed to access any other websites. You are not allowed to access files from your directory, or files from any other user's directories. Failure to abide by these rules is a violation of Academic Integrity, and will be treated as such.
Create a function convert_to_camel(an_identifier)
,
which takes a string as its only parameter which represents the name of a
valid python style identifier witten in "snake case".
Your function should return a string, the camel case version of the
parameter an_identifier.
An identifier witten in snake case contains underscores separating "words" that make up the identifier. For example, "convert_to_camel" is an identifier written in snake case. In camel case, each word (beyond the first word) begins with a capital letter. The camel case version of the previous identifier is "convertToCamel".
To convert from snake case to camel case, the function should capitalize lowercase letters that are immediately preceded by an underscore and remove all underscores. If a character preceded by an underscore cannot be capitalized, the character should not be changed. All characters not immediately preceded by an underscore should also remain unchanged.
>>> print(convert_to_camel("cApitalize__the_1st_letter")) cApitalizeThe1stLetter
Create a function list_of_letters(a_string)
, which takes a
string as its only parameter. Your function should return a list of
unique characters that do not exist within the parameter
a_string.
Your returned list should be in alphabetic order. In addition, the list should only contain lowercase letters, and should not contain any duplicates. Note that an uppercase letter does count as existing within the parameter string.
>>> print(list_of_letters("This is unique!")) ['a', 'b', 'c', 'd', 'f', 'g', 'j', 'k', 'l', 'm', 'o', 'p', 'r', 'v', 'w', 'x', 'y', 'z']
Create a function count_columns(a_2d_list, a_list)
,
which takes 2 parameters: a \(m \times n\) 2 dimensional rectangular list,
and a single dimensional list of length \(m\). Your program should return
an integer, a count of the number of columns of a_2d_list which
are equal to the value of a_list.
>>> test_2d_list = [[0, 1, 2], [3, 4, 5]] # a 2 x 3 2-dimensional list >>> print(count_columns(test_2d_list, [0, 3])) 1 >>> test_2d_list = [[0, 0], [1, 1], [2, 2]] # a 3 x 2 2-dimensional list >>> print(count_columns(test_2d_list, [0, 1, 2])) 2
Create a function left_rotate(a_2d_list)
, which
takes a single parameter: an \(m \times n\) 2 dimensional
rectangular list. Your program should return an \(n \times
m\) 2 dimensional rectangular list. The returned list should
contain the contents of the parameter list rotated to the
left. In a left rotation, each column of a two-dimensional
list, in reverse order, is a row in the rotated
two-dimensional list.
>>> test_2d_list = [[0, 1, 2], [3, 4, 5]] # a 2 x 3 2-dimensional list >>> print(left_rotate(test_2d_list)) [[2, 5], [1, 4], [0, 3]] #[[2, 5] # [1, 4] # [0, 3]]
Write a function compute_pascal
in a file
called bonus_1.py, which takes an integer ≥ 1, and
returns the pascal triangle of the specified depth. Pascal's
triangle can be represented as a jagged 2-dimensional list, where
each row is defined based off the previous row. Row 1 is always
defined as [1]. For every subsequent
row i, each
element j is defined as the sum of
elements j and
j - 1 from row i -
1. if either j - 1 or j do not exist in row i - 1, substitute the value 0 in their place.
>>> print(compute_pascal(1)) [[1]] >>> print(compute_pascal(2)) [[1], [1, 1]] >>> print(compute_pascal(6)) [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1]] >>>
(5 points)
When you have finished, create a tar file of your final
directory. To create a tar file, execute the following commands:
cd ~/cs120 tar czvf final.tgz final/
To submit your coding activities, go to inquire.roanoke.edu. You should
see an available assignment called Final Bonus
.