15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6.22. Exercises<br />

6-1. Strings. Are there any string methods or functions in the string module that will help<br />

me determine if a string is part of a larger string?<br />

6-2. String Identifiers. Modify the idcheck.py script in Example 6-1 such that it will<br />

determine the validity of identifiers of length 1 as well as be able to detect if an<br />

identifier is a keyword. For the latter part of the exercise, you may use the keyword<br />

module (specifically the keyword.kwlist list) to aid in your cause.<br />

6-3. Sorting.<br />

a.<br />

b.<br />

Enter a list of numbers and sort the values in largest-to-smallest order.<br />

Do the same thing, but for strings and in reverse alphabetical (largest-tosmallest<br />

lexicographic) order.<br />

6-4. Arithmetic. Update your solution to the test score exercise in the previous chapter<br />

such that the test scores are entered into a list. Your code should also be able to come<br />

up with an average score. See Exercises 2-9 and 5-3.<br />

6-5. Strings.<br />

a.<br />

b.<br />

c.<br />

Update your solution to Exercise 2-7 so that you display a string one character<br />

at a time forward and backward.<br />

Determine if two strings match (without using comparison operators or the cmp<br />

() built-in function) by scanning each string. Extra credit: Add caseinsensitivity<br />

to your solution.<br />

Determine if a string is palindromic (the same backward as it is forward). Extra<br />

credit: Add code to suppress symbols and whitespace if you want to process<br />

anything other than strict palindromes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!