Game Development Reference
In-Depth Information
Topics Covered In This Chapter:
— Hard-coding
— Augmented Assignment Operators, += , -= , *= , /=
— The random.shuffle() Function
— The sort() List Method
— The join() List Method
— String Interpolation (also called String Formatting)
— Conversion Specifier %s
— Nested Loops
In this chapter you will learn a few new methods and functions that come with Python.
You will also learn about augmented assignment operators and string interpolation. These
concepts don't let you do anything you couldn't do before, but they are nice shortcuts that
make typing your code easier.
Bagels is a simple game you can play with a friend. Your friend thinks up a random 3-
digit number with no repeating digits, and you try to guess what the number is. After each
guess, your friend gives you clues on how close your guess was. If the friend tells you
"bagels", that means that none of the three digits you guessed is in the secret number. If
your friend tells you "pico", then one of the digits is in the secret number, but your guess
has the digit in the wrong place. If your friend tells you "fermi", then your guess has a
correct digit in the correct place. Of course, even if you get a pico or fermi clue, you still
don't know which digit in your guess is the correct one.
You can also get multiple clues after each guess. Say the secret number is 456, and your
guess is 546. The clue you get from your friend would be "fermi pico pico" because one 183
Search WWH ::




Custom Search