As usual, create two directories for today's class. Create a
directory called lecture23
under activities, and
a directory called lab23
under labs.
It's that time again. This one spans back before break! Including activities from lectures 20, 21, and 22.
In a file called string_operations
, Write a function
called slice
. This function takes 3 parameters: A
string, and two integer parameters. The first integer parameter
specifies a starting index, and the second integer parameter specifies
an ending index. Your function should return a "substring" of the
string input parameter, which is a string of all characters in the
range from start (inclusive) to end (exclusive).
Don't forget to define your test cases. Your program should execute your test cases automatically.
On Wednesday, we took a look at how numbers are represented in Binary,
so our computers can actually understand and store them. However, we
really focused on Integers. While that works for Integers (obviously)
and Characters (remember the ord
function?), that doesn't
quite cut the mustard as far as floating point numbers. Let's take a
brief look at how we can represent floating point numbers in Binary.
Since I'm not going to be here on Monday, you get two lectures for the price of one today! Let's examine some more things that the String class provides for us. Specifically:
For those of you not aware, there is a dialect of English out on the web known as "Leet Speak." Leet Speak is simply a textual substitution of characters within some string, which makes the text (purposefully) harder to read, and should be such that only the "elite" of the Internet can really understand it.
Create a file called leet_speak.py
in your lecture23
directory. You should write a function convert_to_leet
that takes a single parameter, a string,
and returns the Leet Speak equivalent of the input string.
You should use the built in replace
method to accomplish
this, following the table below. Ignore the case of the original
characters.
Original Character | New "Character" |
---|---|
a | @ |
e | 3 |
i | ! |
o | 0 |
u | |_| |
l | 1 |
m | /\/\ |
r | |2 |
s | $ |
t | 7 |
w | \/\/ |
Don't forget to define your test cases. Your program should execute your test cases automatically.
Pig Latin is a somewhat silly language parody that is actually entirely English based. It is a simple transposition of letters that gives the effect of a "foreign" sounding language. However, even Thomas Jefferson couldn't resist writing letters to his friends in Pig Latin. The rules for converting an English word to Pig Latin are incredibly easy:
For example, the word scram becomes am'scray, while the word immediate become immediateyay.
Your goal for this assignment is to write a function
convert_to_pig_latin
, in a file called
pig_latin.py
. This function should take a string of
alphabetic characters, and returns a string of alphabetic characters,
the Pig Latin equivalent of the input word.
Your program should gracefully handle capitalization of words. For example, Hello should become Ello'hay, as opposed to ello'Hay. It may be useful to take a look at the string methods Python provides, to reduce some of this overhead.
When you have finished, create a tar file of your lab23
directory. To create a tar file, execute the following commands:
cd ~/cs120/labs tar czvf lab23.tgz lab23/
To submit your activity, go to cseval.roanoke.edu. You should
see an available assignment called Lab Assignment 23
. Only
one of your pair should submit your activity. Make sure both partners
are listed in the header of your files.
Do not forget to email your partner today's files!