UR-Self-Service account (uregina.ca account)
- Login on any campus computer.
- Search, register for classes, printing, email and more. U of R account
Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is widely used to perform all kinds of computer tasks from web applications to processing financial data, including:
When you study Python, quite often you will encounter a discussion on "compiled verses interpreted".
Wikipedia describes Python as an interpreted high-level programming language. https://en.wikipedia.org/wiki/Interpreter_(computing)
A compiler transforms high-level programs (source code) written by humans into the machine code that a (computer can directly execute) which are 0's and 1's in binary.
An interpreter is a program that simulates a computer that understands a high-level language.
The difference between interpreting and compiling is that compiling is a one-time translation; once a program is compiled, it may be run over and over again without further need for the compiler or the source code. In the interpreted situation, the interpreter and the source are needed every time the program runs. (John Zelle. Python Programming: An Introduction to Computer Science. 3rd Edition)
Is Python interpreted or compiled language? https://nedbatchelder.com/blog/201803/is_python_interpreted_or_compiled_yes.html
Replit is an online compiler, IDE, Editor, Interpreter and REPL for more than 50 programming languages. It is a zero setup for online Python programming. Replit
You need to apply for a free Replit account. How to sign up for a free Replit account
The video will guide you in applying for a Replit account with a meaningful username.
When creating your Replit account, it is important to choose a username that allows instructors to properly identify and mark your assignments. For example, my name is
Once you have a Replit account, you can start your first Python program.
Here are some videos on creating python programs on Replit.Since Replit is an online Python IDE, access depends on a working internet connection and the website being operational. The free Replit account allows up to three active projects and a maximum usage of 10 hours per month.
Download Python as described in the next section:We focus on Python 3. Make sure to install Python 3, not Python 2. The latest version of Python can be downloaded at https://www.python.org/downloads/
PCs and Macs might have Python already installed. To check if you have python installed on a Windows PC or Mac.
Check to see if you have Python or not.You can download Python for Windows, Linux/UNIX, Mac OS, and others. Download Python
2. You need a Python IDE. For example, Spyder, Atom, VS code, Pycharm, repl.it which is an online Python Interpreter (Compiler), and many more.
An IDE (Integrated Development Environment) normally has a source code editor, build automation tools, and a debugger.
For our students, the simplest way to install Python and all the scientific libraries you need is to use the Anaconda
distribution, which includes the free:
Spyder integrated development environment (IDE) for Python.
It also includes Jupyter notebooks
for people who prefer to interact with Python using a web-based applications.
Spyder also includes Pyflakes which is
a spellchecker and grammar checker combined into one. It runs in the background when you are editing a Python program
using Spyder. If there is an error in your code, Pyflakes flags the error at the line of code by displaying
a red circle on the left of the line where it thinks the error occurs. Sometimes, the error
actually occurs in the previous line, so look before and after the line of code.
The Spyder IDE is bundled with the Anaconda distribution, and can be found at https://anaconda.com/download/
Here are several videos on using Spyder for Python programming.
First Steps with Spyder
Full Introduction to SPYDER - The Best Python IDE for Data Science
Using the Microsoft Python extension makes VS Code a Python editor that can work on any operating system with a variety of Python interpreters.
PyCharm is an IDE for Python created by JetBrains for computer programming, specifically the Python language. PyCharm Community Edition is free and open-source, available under the Apache 2.0 license.
Download Pycharm (The Python IDE), make sure to choose the community version.
Other list of Python IDEs to choose from.
Python syntax can be executed by writing directly in the Command Line. For example, you can type the following lines in the Replit Python console, and you will see:
Python 3.8.12 (default, Feb 26 2022, 02:56:10) >print("Hello, CS students!") Hello, CS students! >print(2+2) 4 >print("2 + 2 = ",2+2) 2 + 2 = 4 >
>
is a Python prompt indicating the interpreter is waiting for a command. A complete command is called a statement.
There are three examples of print statement above.
Try to type the following code in the Python Command Line:
When you type the first line, then press Enter, the ... is automatically displayed at the beginning of the line, it means the statement is not finished, Python is waiting for more.
>def main(): ... print("Hello, CS students!") ... > main() Hello, CS students! >
Here is an example of creating a Python program called main.py
# Student Name:
# Student #:
# Replit username:
# Lab #/Asg#:
# File: main.py
def main(): #6 Function name is called main.
print("Hello everyone!") #7 Indented print() line to show this is part of the main function.
print("Have fun learning Python.")
main() #9 The last line of the file is the command to invoke (call) this function.
To execute the main.py program using Replit, simply click on the Run button. However, if the program name is not main.py but rather hello.py, you will need to compile and run the program in the shell window. To do so, click on the Shell window tab located on the right of the console window. Then, type the following command in the Shell window:
python filename.pyReplace "filename" with the name of your program file, in this case, "hello.py". This will compile and run your program.
Indentation refers to the spaces at the beginning of a code line.
Python uses indentation to indicate a block of code.
Python uses a sequence of statements together to create a new command or function.
https://www.w3schools.com/python/gloss_python_indentation.asp
Comments starts with a #, and Python ignores them:
https://www.w3schools.com/python/python_comments.asp
Note: line 6, def main(): and line 9, main() are not required. Nonetheless, these two lines are included in all lab materials as a means of preparing students for the concept of functions in subsequent labs.
You can use either an online Python IDE, such as Replit, or any desktop Python IDE, such as Spyder to write the following program.
def main(): # function name is called main. print("Python is a popular programming language.") print("25 + 25 = ", 25+25) print("3 * 67 = ", 3*67) main() # The last line of the file is the command to invoke (call) this function