Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Raspberry Pi Projects for Kids (Second Edition)

You're reading from   Raspberry Pi Projects for Kids (Second Edition) Leverage the power of programming to use the Raspberry Pi to create awesome games

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher
ISBN-13 9781785281525
Length 146 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Daniel Leonard Bates Daniel Leonard Bates
Author Profile Icon Daniel Leonard Bates
Daniel Leonard Bates
Arrow right icon
View More author details
Toc

Complete code listing

Here is the final code you should have when you have completed this chapter. You can use this code listing to check that you have everything in the right order, or look for other problems in your code. Of course, you are free to change the contents of the lists and dictionaries to whatever you like; this is only an example:

import random

def chooseAdjective(tag):
    while True:
        item = random.choice(adjectives.keys())
        if adjectives[item] == tag:
            break
    return item

names = ["Alice", "Bob", "Carol", "Dave"]
adjectives = {"fast":"good", "slow":"bad", "pretty":"good", "smelly":"bad"}
nouns = ["dog", "car", "face", "foot"]

name = random.choice(names)
#adjective = random.choice(adjectives)
noun = random.choice(nouns)

if name == "Alice":
    adjective = chooseAdjective(&quot...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime