Python Programming for Kids Beginners Guide with Easy to Learn Activities to Unlock the Adventurous World of Python… (Simon Weber) (Z-Library)
Author: Simon Weber
Python
No Description
📄 File Format:
PDF
💾 File Size:
1.8 MB
5
Views
0
Downloads
0.00
Total Donations
📄 Text Preview (First 20 pages)
ℹ️
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
📄 Page
1
(This page has no text content)
📄 Page
2
Python Programming for Kids Beginners’ Guide With Easy-to-Learn Activities to Unlock the Adventurous World of Python Programming Author Simon Weber © Copyright 2019 - All rights reserved. The content contained within this book may not be reproduced, duplicated or transmitted without direct written permission from the author or the publisher. Under no circumstances will any blame or legal responsibility be held against the publisher, or author, for any damages, reparation, or monetary loss due to the information contained within this book. Either directly or indirectly.
📄 Page
3
Legal Notice: This book is copyright protected. This book is only for personal use. You cannot amend, distribute, sell, use, quote or paraphrase any part, or the content within this book, without the consent of the author or publisher. Disclaimer Notice: Please note the information contained within this document is for educational and entertainment purposes only. All effort has been executed to present accurate, up to date, and reliable, complete information. No warranties of any kind are declared or implied. Readers acknowledge that the author is not engaging in the rendering of legal, financial, medical or professional advice. The content within this book has been derived from various sources. Please consult a licensed professional before attempting any techniques outlined in this book. By reading this document, the reader agrees that under no circumstances is the author responsible for any losses, direct or indirect, which are incurred as a result of the use of information contained within this document, including, but not limited to, — errors, omissions, or inaccuracies.
📄 Page
4
Table of Contents Introduction Chapter One: What Is an Algorithm? Algorithm You Can Write Your Own Algorithm Benefits of Algorithmic Thinking Understanding the Basic Algorithm That Digitally Powers Life Search and Recommendation Algorithms Sort Algorithms Algorithms in Your Life Chapter Two: Not All Languages Slither A Little More About Python Installing Python Installing Python on Windows Installing Python on Mac OS X Installing Python on Ubuntu What’s Next? Saving the Program What You Learned Chapter Three: Python Variables Calculating With Python Python Operators Order of Operations Variables Are Like Labels Using Variables What You Learned Chapter Four: Strings, Lists, Tuples, and Maps Strings Creating Strings Error Handling With Strings Embedding Values in Strings Multiplying Strings Lists Trump Strings Adding Items to Lists Removing Items From Lists Arithmetic in Lists Tuples
📄 Page
5
You Cannot Use Python Maps to Find Your Way! What You Learned Exercises Chapter Five: Drawing With Turtles Using Python’s Turtle Module Creating a Canvas Moving the Turtle What You Learned Exercises Chapter Six: Asking the Right Questions If Statements Block of Statements Conditions Help Us Compare Things If-Then-Else Statements If and Elif Statements Combining Conditions None – Variables With No Value Difference Between Strings and Numbers What You Learned Exercises Chapter Seven: Using Loops Using Loops While We Continue to Talk About Loops What You Learned Exercises Chapter Eight: Working With Functions and Modules Using Functions Parts of a Function Scope and Variables Using Modules What You Learned Exercises Chapter Nine: Complex Programs Bubble Sort Algorithm Insertion Sort Algorithm Selection Sort Algorithm PageRank
📄 Page
6
Chapter Ten: Building Games Using Arcade Simple Drawing Using Functions The Window Class Sprites Creating a Sprite Sprite Lists Detecting Sprite Collisions Game Physics Top-Down Games Chapter Eleven: Simple Games Color Game Using Tkinter Rolling the Dice Guessing Game Guessing Game Version Two Hangman Magic Eight Ball Mad Libs Shuffling a Pack of Cards Tic Tac Toe Simple Graphics Using Turtle Drawing a Triangle Using Python Testing Animation and Depth Drawing a Face Animation Using Groups of Objects Chapter Twelve: Bunnies and Badgers Step 1: Hello, Bunny Step 2: Add Scenery Step 3: Make the Bunny Move Step 4: Turning the Bunny Step 5: Shoot, Bunny, Shoot! Step 6: Take Up Arms! Badgers! Step 7: Collisions With Badgers and Arrows Step 8: Add a HUD With Health Meter and Clock Step 9: Win or Lose Step 10: Gratuitous Music and Sound Effects! Conclusion
📄 Page
7
References
📄 Page
8
Introduction I want to thank you for choosing this book, Python Programming for Kids - Beginners’ Guide With Easy-to-Learn Activities to Unlock the Adventurous World of Python Programming. Why is it important to learn how to program? When you learn how to program, you can improve your creativity, problem- solving abilities, and reasoning skills. Programmers always have the opportunity to create or build something from nothing. They can turn logic into a code that helps a machine perform actions and functions that it will normally not d0. They also spend time trying to understand why a specific code has not worked or what they can do better to improve how the machine works. Programming is a challenging and fun activity, and the skills that you develop through programming will help you in school and work. You don't necessarily have to work with computers to make use of the skills that you develop, though. If nothing else, you can program to make good use of your time. If you are interested in computer programming, this book is for you. This book is titled Python for Kids, but adults can also use it if they are working on the matter for the first time. To understand more about the building software and avoid depending on the applications available on the Internet, this is a great place to start. In this book, you will learn how to install Python, open the shell, as well as perform basic calculations, create lists, and print data on the screen. You can learn more about improving the flow of the program using loops and conditional statements, too. Furthermore, you can figure out how to reuse code within functions, the descriptions of some modules and functions in Python, and the basics of objects and classes. So, why Python? Python is an easy programming language with some useful features that a beginner can learn about. It is easy to read the code since it is a high-level programming language. The best part about Python is that you can run all the codes on an interactive shell that allows you to see the program you have written run. Apart from being a programming language that is easy to understand, Python also provides some features that make it easy for a
📄 Page
9
programmer to build games or any other application. One such module is the Turtle module. It was inspired by Turtle graphics and designed specifically for educational purposes. Another example is the tkinter module that acts as an interface for a GUI toolkit called Tk. This interface allows programmers to create complex programs using advanced animation and graphics. You may now be wondering how you should learn to code. When you learn something for the first time, you always begin from the basics. You should, therefore, begin with the first chapter and slowly progress into the remaining chapters. Do not skip to the later chapters and have no idea about what you are doing. You can never expect a student pilot to fly a plane after his or her first class, can you? If you do not follow the right order, you will not know the basics and find that the rest of the content is hard to understand and slightly more complex than they are. When you go through this book, you must ensure that you try the examples provided in every chapter and understand how each of them works. There are some exercises given at the end of most chapters as well, and it is important to work on them to improve your skills. It will be easier to figure out some complex ideas if you know the basics of programming fully. If there is something that you are unable to understand, and it is frustrating for you, you should try the following: 1. Break the large problem into smaller segments and try checking every line of code. You can also worry about a smaller part of the idea before you focus on writing the code. 2. If this does not help, ignore the program for a while and go play with your friends. You can come back the following day or a few hours later and then look at the problem again. This is a very good way to solve the problem. You will find that the chapters in the book are simple; you will also learn more about creating graphics using turtle in Python. There are some exercises present at the end of some chapters, and the complexity of the questions varies across them. This will test your understanding and give you the chance to build small programs. When you realize the fundamentals of the language, you can learn to create your games and develop excellent graphics. You will also know about events, collision detection, and different techniques to animate processes.
📄 Page
10
Most of the examples in the book are written in Python’s Integrated DeveLopment Environment (IDLE). This interface will highlight the incorrect syntax, help you copy and paste code, and edit it for later. This means that IDLE works as an interactive environment and test editor. The examples in the book will function in the same way in the console, but the IDLE is a better interface to use since you will know exactly where there are errors. This is a user-friendly environment that will help you build a program faster than when you use the console. It is important to remember that programming can be fun, and you should never think of it as work. You should always look at it as a way to create some exciting applications or games that you can share with other people via the Internet. The results of programming can be rewarding, and it is important for you to remember that you should have fun irrespective of what you do!
📄 Page
11
Chapter One: What Is an Algorithm? Most kids are unaware of what an algorithm is because it is not relevant to kids. However, this is far from the truth. An algorithm is all around you. You can govern everything right from technology to the easiest processes using an algorithm. It does not always have to be complex since you can write simple algorithms. So, let us understand what it means. Algorithm An algorithm is a basic formula or a step-by-step instruction that you can use to complete any task or solve any problem. A programmer will use it to tell a machine or computer how it should perform a specific task. If you do not look at an algorithm in the most technical way, you will realize that it exists almost everywhere. Say, your mother or grandmother may use a recipe to prepare a dish. This recipe is an example of an algorithm. Alternatively, your teacher may have told you to use a specific method to solve a problem in arithmetic. Did you know that your morning routine is also an algorithm? As a simple exercise, take a piece of paper and list down what you do every morning. You Can Write Your Own Algorithm If you do not want to write down an algorithm about your entire morning routine, you can write about simpler tasks like eating cereal or brushing your teeth. You will soon learn about some important concepts of programming, such as sequencing (putting the cereal in a bowl and then pouring milk), conditional logic (do not eat if the bowl is empty), and repetition (brush the bottom row of teeth four times). If you want to become better at writing algorithms, you should try to add a few more challenges. A computer will never understand what your intentions are if you do not explicitly define something. If you do not tell the machine that it should fill milk in the bowl only after a bowl is placed in front of it, for instance, you will end up wasting quite a bit of milk.
📄 Page
12
In your arithmetic class, you may have also learned about prime numbers and how you can determine them. This is hard to do with large numbers like 497; you may need to try at least 1o calculations before you can figure out whether the number is prime or not. Benefits of Algorithmic Thinking It is important to have the ability to define steps clearly when you solve a problem in science or mathematics, and this type is known as algorithmic thinking. Most children use algorithms in subjects like mathematics and do not realize that they are following such a technique to resolve a question. For example, if you are trying to solve a long division problem, you will apply the algorithm and divide every digit in the number that you are using. For every dividend and divisor, you should multiply, subtract, and divide the numbers. Through algorithmic thinking, you can learn to break a problem down and conceptualize solutions on the basis of the procedure that you should follow. A kid can always improve his ability to think by working on some programming. They should try to complete exercises and puzzles that will improve their algorithmic thinking skills. These activities can refer to problems that revolve around repetition, conditional logic, or sequencing. A child should always practice simple and complex questions to improve their cognitive process. Understanding the Basic Algorithm That Digitally Powers Life Every algorithm will provide a set of instructions that the machine or computer must follow to obtain the solution. They are the base of all technology. The algorithm can be used to solve any type of problem, including compressing a file, determining the pages on the internet that have the most relevance to your search, or sorting a list. It will also allow you to determine the way a traffic signal should work, how the postal services or any other courier service can deliver mail and many more. In this age, it is important for a child to learn more than just how to use technology. It is essential for them to explore different algorithms that, say, power the television at home or their phones. They should also understand
📄 Page
13
the algorithms used on different social media websites. This will help them improve their programming skills and work on creating new technology. Search and Recommendation Algorithms What happens when you enter a query on Google? How do the right pages show up on your screen? Google uses a special algorithm to sift through the Internet and determine the pages that match your query. It will post the links that have the highest rank on the top. The PageRank algorithm will consider the number of websites connected to the webpage you are looking for and rank is based on the ranking of the pages linked to it. It will return the list of web pages that you can look at in a matter of seconds. Many algorithms used on social media platforms will try to build connections as well. These algorithms do this by calculating the degrees of separation between users. For example, if you are friends with George, and George is friends with Richard, the algorithm will assume that you know Richard. It will suggest that Richard is a potential connection. Nevertheless, if you are friends with George, George is friends with Richard, Richard is friends with Daryl, Daryl is friends with Erin, Erin is friends with Ben, and Ben is friends with John, the algorithm will not suggest John as a connection because the degree of separation is very high. When you use Netflix or Amazon, the algorithms will recommend different movies and shows that you may want to watch, as well as products that you can purchase based on your likes. Sort Algorithms You are always following an algorithm when you choose to perform a specific action. You may not be aware of it consciously, but you do it anyway. A sorting algorithm is important since the computer will need to sort through large quantities of data quickly to provide you with the right output. Let us look at another exercise. How would you tell someone who does not know about sorting to organize 10 books in alphabetical order? You will say that the person should look at the titles of every book and make note of the letter that the name starts with. You will first inform them how to do it with one book, two books until they
📄 Page
14
can sort everything. How do you think you can explain it to someone who will need to arrange hundreds or thousands of books? This task will take the person hours or perhaps days to finish! This algorithm is similar to the insertion sort algorithm. For its purpose, you can create a simple list that the system can use. It will only become a complex algorithm if you are using a larger list. Alternatively, you can choose to sort the books randomly. You can tell that individual to arrange the data by comparing the titles on different books that have been placed next to each other. To do this, they can compare the first book with the second one. If they are in order, you can ask the person to swap the books, then compare the second and third books, and choose to swap them if necessary. Once the person reaches the end of the list, he will need to go back to the first two books and begin to compare them again. This will need to be done until the books are sorted in alphabetical order. This algorithm is known as the bubble sort algorithm. It is a good idea to use this technique on small lists, but not for long lists. Algorithms in Your Life If you want to build a tool that can run quickly and efficiently, you must write algorithms for sorting and searching for the right information. These two are the most basic algorithms in the programming world, and many applications including YouTube and mobile face scanners on your parents’ phones use them. If you do not believe what you are reading, think about it. How can YouTube stream all the videos on your parents’ phones without any hiccups? Alternatively, how can your parents’ phones recognize their faces and unlock the devices that way but not if it scans another person’s face? You may think that your computer or phone is so smart and knows how to make the decisions the same way that a human being can. The machine can do this because someone has spent enough time to help the machine learn how it can do so using a complex algorithm. This programmer would have told the machine how it should perform specific functions with some logic or probability. When you understand what an algorithm is, you can open up a world of possibilities for yourself. You can learn how to effectively use them and start
📄 Page
15
building the best applications or programs using some complex algorithms.
📄 Page
16
Chapter Two: Not All Languages Slither You can instruct a computer to perform a specific action by giving it some functions, which are all detailed in a computer program. A program is not the physical aspect of a computer. The wires, cards, hard drives, microchips, and other similar parts do not perform these tasks. It is the hidden stuff within the hardware that can be used to perform specific functions. A computer program is a specific set of commands that will inform the computer that it must do something. The software in a system is a collection of multiple programs. If you do not have any computer program, every device that you normally use will either stop working or not become as useful as it has been. A computer program, regardless of its form, will control not only the PC but any video game as well. Computer programs also handle GPS units in cars. If you have a smart TV at home, you can be rest assured that there is a computer program that tells the appliance how it should understand what you want it to do. Even elevators are controlled by a program. A program is more like a thought. If you did not have any thoughts, you will sit on the couch in your house and stare vacantly in one direction. You may also drool down the front of your clothes. When you think, “Get off the floor,” your brain will command your muscles to move. A computer program works in a similar way. It will instruct the computer about what it should do. You can work on numerous tasks and activities if you know how to write a program. You may not be able to do so to control the traffic lights or cars - at least not right now - but you can create your own applications and games. A Little More About Python Computers are similar to humans, in the sense that they also use different languages to communicate with each other. In this case, it is programming languages. A programing language is one of the simplest ways to talk to a computer. It will allow you to give instructions to the device, which both you and the
📄 Page
17
computer can understand. Python is one such language. Although it was not named after the snake, it got the name from a TV Show, Monty Python’s Flying Circus. There are many features and functions that the language offers and makes it important for beginners to learn. You can use Python to write efficient and simple programs in a matter of minutes, for one. There are no complicated words or symbols that you need to use when you write the code, too. Thus, it will be a great idea to learn this language over other programming languages. Installing Python It is easy to install Python on your system. In this section, in particular, we will learn more about how you can install Python on Windows 10 or 7, Mac OS X, and Ubuntu. When you are installing Python, you will also be able to set up a shortcut for the IDLE program. This program is the Integrated Development Environment in which you can write all the Python programs. Installing Python on Windows If you want to install Python on Windows 10 or 7, you should go to the following website and download the latest version of the Python 3 installer for Windows: http://www.python.org/. You can find the installer in the Quick Links section. After doing so, click on the icon and follow the instructions that appear on the screen to install Python. You must remember, however, that it will only be installed in the default location. You should select Install for all users. Click Next. Do not change the default directory, but ensure that you write the name of the installation directory. Click Next. Do not choose to customize Python when you are installing it
📄 Page
18
Click Next. You will have Python 3 on your system at the end of the installation. If you wish to add a shortcut to the desktop, follow the steps given below: Right-click on the desktop and select New Shortcut from the menu. When you are prompted to enter the location of the item that you want to create a shortcut of, enter this code: c:\Python32\Lib\idlelib\idle.pyw–n Click Next to move to the next window. Before you click Finish, change the name of the shortcut to IDLE. Installing Python on Mac OS X Python comes pre-installed in Mac OS X. The version of the language, though, is old, so it is important to update it to the latest one. To be able to do that, go to the following website and download the newest version of Python: http://www.python.org/getit/. You can use two installers for this purpose. You should download one that is compatible with the Mac OS X version that you have on your system. If you do not know what the version is, go to the Apple icon in the Menu bar and choose the option About this Mac. You should download the 32-bit version of Python 3 for i386/PPC if you are using a Mac version between 10.3 and 10.6. You should download the 64-bit or the 32-bit version of Python 3 for x86-64 if you are using the 10.6 or a higher version of Mac OS X. When the files are downloaded, there will be a name with the extension .dmg. Double-click on that file and look at the window that opens up. Read the content present in it; you should double-click on the Python.mpkg file and follow the instructions given to install the software. You should ask your
📄 Page
19
parents to sit with you when you are doing this to ensure that you install the software correctly. You will be asked for the administrator password. You should then add the script to the desktop before you can launch the IDLE application. You should click on the magnifying glass icon at the top-right side of the screen. This is called the Spotlight icon. Enter the word Automator in the box that appears. A menu will then open. You should click on the Robot like icon. It will be in the section labeled Applications or Top Hit. Once this starts, you should select the Application template. You should choose to continue. Run the Shell script and drag it to the empty section on your right. You will see the word cat in the text box on your screen. You should now select that word and replace it with this full text: open -a "/Applications/Python 3.2/IDLE.app" --args -n You can choose to change the directory based on the Python version that you have installed. Enter IDLE as the name and save the file down. Choose to save the icon on the desktop. Installing Python on Ubuntu The Ubuntu Linux distribution comes installed with Python, but there is a possibility that it is an older version as well. If you want to install the latest version of Python, follow the steps given below: Go to the Sidebar and select the Ubuntu Software Center. This is an icon that resembles an orange bag. If you cannot find the icon on the Sidebar, you should go to the Dash Home icon and enter the name of the software in the dialog box. You should type the word Python in the search bar now in the
📄 Page
20
Software Center. Choose the latest version of the IDLE from the list of software presented to you. Click Install. If you have an administrator password, call your parents and ask them to enter it. You should then click on Authenticate. The latest version of Python is now being installed. What’s Next? Once you have Python installed, you will find an icon labeled IDLE on your desktop if you are using Mac OS X or Windows. If you have Ubuntu, you will need to go to the Applications menu. You will see a folder or group called Programming, which will have the application IDLE. You can either choose the menu option or double-click on the icon. The Python shell will open, and it is a part of the IDLE. You will always begin a program with the sign >>> that is known as the prompt. You should then enter some commands at the prompt. >>> print("Hello World") Always include the double quotes inside the parenthesis. We will learn more about why it should be done in this way later. Once you have finished typing the line out, you should press Enter. If the command has been entered correctly, this will be your output: >>> print("Hello World") Hello World >>> The prompt will reappear and inform you that you can write more commands in the Python shell. You have created your first program in Python! We have
The above is a preview of the first 20 pages. Register to read the complete e-book.