Teach Your Kids To Code: A Parent-friendly Guide to Python Programming

(vip2019) #1

102 Chapter 5


•    Test a variable to see if it is odd or even using the modulo
operator, %.
• Write if-elif-else statements that select from among a number
of options.
• Use and and or to test multiple conditions at once.
• Use the not operator to check whether a value or variable is
False.
• Explain how letters and other characters are stored as
numeric values in computers.
• Use ord() and chr() to convert characters into their ASCII
equivalents and vice versa.
• Manipulate strings using various string functions like lower(),
upper(), and isupper().
• Add strings and characters together using the + operator.

Programming Challenges


To practice what you’ve learned in this chapter, try these
challenges. (If you get stuck, go to http://www.nostarch
.com/teachkids/ for sample answers.)

#1: Colorful Rosettes and Spirals


For a more visual challenge, look back at the colorful spiral
and rosette image in Figure 5-1 on page 78. You should
be able to modify RosettesAndPolygons.py on page 88 to
make it more colorful and, if you like, replace the polygons
with small spirals to match the illustration in Figure 5-1.

#2: User-Defined Keys


For a more text-based challenge, create an advanced ver-
sion of our EncoderDecoder.py program by allowing the
user to input their own key value, from 1 to 25, to deter-
mine how many letters to shift the message by. Then, at the
line marked y in EncoderDecoder.py (page 99), instead of
shifting by 13 every time, shift by the user’s key value.
Free download pdf