Python VI
Mary PW Chin 钱碧慧博士 PhD (Wales), MSc (Surrey) E-mail:
Strings & text processing
Data file:
☞ download cutting.txt
Slides here are continuously being revised and updated. If you have been here before, your browser might have some old files cached. To ensure that you see the latest version, please follow the instructions given in the following link: ☞ how to clear browser cache .
Gentle reminder
For every program you encounter it is always an excellent exercise to change the variable names to names which are most meaningful to you, then make the program run. You will gain deeper understanding of the program. You will see the program in a new light. Everyone is different: variable names most intuitive to me differ from variable names most intuitive to you. My programs are written with variable names most intuitive to me, so you should change them to names most intuitive to you so that the program flow becomes more obvious.
Synopsis
Lists;
append ing to list;
len gth of lists;
join ing lists;
reverse -ing lists;
sort ing lists;
count ing lists;
read ing text files;
strip ing strings;
the re gular expression module and its split and sub stitute methods;
the random module and its shuffle method.
enumerate ;
ord ;
encryption and decryption: proof of principle.
Exercises
Write a program to print the following with a for loop:
DELIGHT
TDELIGH
HTDELIG
GHTDELI
IGHTDEL
LIGHTDE
ELIGHTD
Write a program to print the following with a for loop:
WONDERFUL
OWONDERFU
NOWONDERF
DNOWONDER
EDNOWONDE
REDNOWOND
FREDNOWON
UFREDNOWO
LUFREDNOW
Write a program to print the following with a for loop:
WONDERFUL
ONDERFULU
NDERFULUF
DERFULUFR
ERFULUFRE
RFULUFRED
FULUFREDN
ULUFREDNO
LUFREDNOW
Write a program to encrypt and decrypt your output from Excerise 1. Use an encryption method no simpler than that of slide #44.
Write a program to encrypt and decrypt your output from Excerise 2. Use an encryption method no simpler than that of slide #44.
Write a program to encrypt and decrypt your output from Excerise 3. Use an encryption method no simpler than that of slide #44.
Challenge
☞ Journey into Cryptography