Homework Assignment Number 7
- Read ½ of Chapter 6 in Donaldson Book
- Secret Code: write a function that takes a string as an argument
and prints out a new string consisting of numbers divided by spaces.
- These numbers should be derived by using the ord function on
each character.
- It is suggested that you use a for loop to solve the problem.
The output could begin as an empty string and be built up to the final
solution.
- For example 'cat' should be printed as: 99 97 116
- Download the functions for converting number
strings like 'four hundred and fifty three” into numbers like 453 (any
versions that work).
- Listed on the class website as materials for class on sequences
(the number programs)
- The original problem description was as follows:
- Convert string to lower case
- Tokenize string (split at spaces)
- Given a list of such strings, convert them to a single number
- For a fuller description: see slides 17 and 18 in http://cs.nyu.edu/courses/summer11/V22.0002-001/sequences.pdf
- Write parts 1 (convert string to lowercase) and 2 (tokenize
string) of that code and incorporate the function we wrote in class (do
not worry that the function will not work for large numbers). Use the
string.split function. Get the code to work as a cohesive unit to
convert strings like "two hundred sixty two" to numbers like 262.
- Write two additional functions
- string_multiply
- Takes two strings as input, converts them to numbers and
then multiplies them together (and returns the resulting value)
- string_add
- Takes two strings as input, convert them to numbers
and then multiplies them together (and returns the resulting value)
Grading Criteria
- Does the program work?
- Does it solve the problem described in the question?
- If the question asks to print something out, does your program
print it?
- If it asks to return something, do you return it?
- Is your code well written and clear?
- Are the variable names and function names understandable?
- Do you have adequate comments?
- Do you encapsulate functions for reuse that clarify what you
are
doing? For example, a function “make_upper_case” is clearer than
a loop that adds a certain number to a character code.
- Did you do anything clever?
- Did you solve a more complex version of the problem?
- Is your code elegant?