Discuss Scratch

-FasterThanLight-
Scratcher
100+ posts

The Scratcher's guide to Python

Welcome to The Scratcher's guide to Python! For those who don't know what Python is, Python is a easy-to-learn professional programming language used by big companies including Google and Youtube to use and run their services. This thread is meant to provide a guide for any Scratchers who are interested in moving on to Python. Along the way, you'll learn how to:
  • Create Python programs in a professional code editor.
  • Learn to create your own games in Python.
  • You'll create a functioning website using Flask.
  • And much, much, more!
  • You'll also learn many coding skills, and also have a lot of fun. Yay!

This guide is divided into lessons, where I go over what will be learned/done in the lesson, and then some steps to reach a goal. Then, at the end, you will be challenged to create your own programs, solve quizzes, or make changes to the code you made earlier.

Are you ready? Let's begin.
Lesson #0: Installing Python on your Computer
Does it make sense to have a Lesson 0? I don't know, but before we can do any Python coding, we need to install(i.e. download) Python first.
Warning!!! The instructions for installing Python will differ based on your Operating System. I have tried to list all of the major OSes here, but a quick Google search will work if your OS isn't listed.

Installing Python on Windows
To install Python on a Windows computer, click here to download the Python 3.8.1 Installer. Run the program, and it will guide you through the process of installing Python on your computer.

Installing Python on Mac OS
To install Python on Mac OS, click here to install the .pkg file for Python. Open it up in Finder, then double-click it to install Python. The installer will guide you through the process of installing Python on Mac OS.
Warning!!! In order to install Python, you may need to enter your Mac's password. Ask your parents if you don't know the password.

Installing Python on Debian Linux
To install Python on Debian Linux, open a terminal window and type:
apt-get update && apt-get upgrade && apt-get install python3

Installing Python on Raspberry Pi
If you are using a Raspberry Pi computer, you don't have to do anything to install Python, it's already there!

Now, let's make sure that you've installed Python correctly. Open a terminal, and type either python or python3 exactly. If either of those commands works, you have Python installed on your computer!

Installing a Text Editor
One of a programmers main tools is a Code Editor, which is a tool that allows you to edit your programs, and you will be doing that a lot, so pick one you like. I would suggest clicking one of the links below to install a Code Editor for Python:
  • IDLE: IDLE should be packaged(come with) with some Python installations.
  • Nano: Nano is pre-installed on most Linux versions, and is a fairly nice Text Editor. To use it, open a terminal and type ‘nano’.
  • Notepad++: Notepad++ is a text editor which works on Windows and is free to download.
  • Brackets: Brackets is a free and powerful text editor to use.

That's it for installing Python!
Lesson #2: Hello, world!
If you've completed the installation of Python in Lesson 0, you should now be able to write Python code! Start by opening up your text editor and typing:
1  | # This program prints out the text "Hello, world!"
2  | print("Hello, world!")
Warning!!! Do not enter the vertical bars or numbers on the left of the code! These are line numbers, and are just there to make it easy to refer to a certain piece of code.
On line 1, the text after the # symbol is called a comment. A comment is a piece of code that the computer does nothing with, but can be read by other programmers.
On line 2, is a function call. Functions are little pieces of code that make it easy to perform a certain task that is used a lot, for example printing text, or managing files.
Now, press Control+S on your keyboard, and save your file somewhere useful, like Documents/python-programs, or somewhere else. Save the file as hello.py, and remember where you put it! Now, open a terminal and type:
user@localhost:~/Documents/python-programs$ python3 hello.py
Hello, world!
If you see that output, you made your program correctly! If you see an error, go back and type the code exactly as was shown. If you forget the ( symbol on line 2, you'll get error. Add the ( back, and you should not get an error.

Homework:
How do you print Hello, world!?
Can you make it so that the code displays Goodbye, world! instead of Hello, world!?


Changelog

2/10/2020 4:31 PM: Created lessons 0 and 1.

Suggest new lessons!

If you have any ideas for new lessons, please submit them!
-FasterThanLight-
Scratcher
100+ posts

The Scratcher's guide to Python

Bump!

Powered by DjangoBB