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
Python Projects for Kids

You're reading from   Python Projects for Kids Unleash Python and take your small readers on an adventurous ride through the world of programming

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher Packt
ISBN-13 9781782175063
Length 192 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jessica Ingrassellino Jessica Ingrassellino
Author Profile Icon Jessica Ingrassellino
Jessica Ingrassellino
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Welcome! Let's Get Started 2. Variables, Functions, and Users FREE CHAPTER 3. Calculate This! 4. Making Decisions – Python Control Flows 5. Loops and Logic 6. Working with Data – Lists and Dictionaries 7. What's in Your Backpack? 8. pygame 9. Tiny Tennis 10. Keep Coding! A. Quick Task Answers Index

Write and run your first program in the command line

Now that you are set up, it is time to write your first line of code in Python! This line of code is almost a tradition for people who are programming for the first time, and it allows us to use one of the most basic, but most useful, functions in the Python language.

First, you need to start running a Python shell. On Mac or Linux, open your terminal and type this:

python

In the Mac or Ubuntu terminal, your resulting Python shell will look like this:

>>>

In Windows, type Python in the search bar at the bottom of the page. Then, select Python 2.7.11 from your apps. You will also have a Python shell open:

>>>

Once you see this symbol, your computer is now ready to work with the Python code. In your terminal or IDLE, type the following:

>>>print("Hello, world!")

Once you have typed this, double-check to make sure that all of the spaces are exactly as they've been written. In Python, every space actually matters. Every punctuation mark matters. Once you have checked your code, hit Enter.

What is your result or the output of your code? If the output looks like the following image, then great! You typed all of your code properly so the computer will understand what you want it to do. The expected output will be similar to what is shown here:

Write and run your first program in the command line

For Windows users, the output window will look like this:

Write and run your first program in the command line

So, if your output does not look like the preceding code, you need to figure out what's wrong with it. Here are some of the reasons for this:

  • Did you make a typing error?
  • Did you forget to use parenthesis or round brackets () for the words 'Hello, world!'?
  • Did you forget to use the ''single quotation marks for Hello, world!?

If you still have a problem, compare your code to the sample input code and fix any mistakes. Then, try to run the code again.

Note

Python is what is called a case-sensitive language. Python cares about uppercase, lowercase, and whitespace. You need to watch what you type. You might get some strange messages from your computer if you make a typing mistake or a syntax error.

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 €18.99/month. Cancel anytime