Welcome to the exciting journey of programming! Get ready to learn, create, and have some fun along the way. Let's turn your ideas into reality!
- What is programming?
- Overview of Python
- Python installation
- IDE Installation (VSCode)
print()
input()
- Quiz: Introduction to Programming
- Homework
Programming is the process of creating a set of instructions that tell a computer how to perform a task. It’s like writing a recipe, but instead of making a cake, you’re creating different apps.
Talking of all opportunities which are opened to you after learning how programming works , you will be able to do the following things:
-
Solve Problems: Programming can be used to model and solve complex problems in fields like
finance
,engineering
, andmedicine
. -
Develop Software and Applications: From the operating system on your computer to the apps on your phone, programming is the backbone of software development.
-
Create Websites: Web development involves programming both the visual
front-end
that users interact with and theback-end
that processes data. -
Automate Tasks: You can write
scripts
to automate repetitive tasks, saving time and reducing errors. This could be anything from sorting files to generating reports. -
Analyze Data: With programming, you can process large sets of data to find patterns and insights, a practice commonly known as
data science
. -
Build Games:
Game development
is another avenue, where programming brings to life the mechanics, graphics, and interactivity of a game.
Choosing Python
as your first language opens a world where coding is not just accessible, but also very enjoyable and rewarding.
Aspect | Details |
---|---|
Features | - Easy to Learn - Interpreted - Versatile - Extensive Libraries - Cross-Platform - Open Source - Community Support |
Common Uses | - Web Development (Django, Flask) - Data Science (NumPy, SciPy, Pandas) - Automation (Scripting) - Scientific Computing - Education (Teaching Programming) |
Advantages | - Readable syntax encourages good practices - Low maintenance cost - Free for all major platforms |
Disadvantages | - Slower execution compared to compiled languages - Less prevalent in mobile computing compared to web development |
Over its almost 30 years of existence, Python has become one of the most popular programming languages.
To give you the big picture, let’s take a look at some applications and companies who use this language on everyday basis
Each of these application are using python in a certain way, and as you can see from the statistics it becomes much popular every day
Step 1: Download Python
- Visit the official Python website at python.org.
- Navigate to the Downloads section and download the latest version of Python for Windows.
Step 2: Download Python
- Run the Installer:
- Once the installer is downloaded, run it.
- Make sure to check the box that says
"Add Python to PATH"
before installation. - Click
"Install Now"
to start the installation process.
Step 3: Verify the Installation
- Open Command Prompt and type
python --version
and pressEnter
. - If Python is installed correctly, you should see the version number.
Step 1: Download Python
- Visit the official
Python
website at python.org. - Under the Downloads section, choose the macOS version and download it.
Step 2: Run the installer
- Click
"Install Now"
to start the installation process.
Step 3: Verify the Installation
- Open
Terminal
and typepython --version
and pressEnter
. - The version number should appear if the installation was successful.
To start coding, we need two main things: a development environment where we can write our code, and the Python
to execute it.
Step 1: Downloading VSCode
- Navigate to the Visual Studio Code website.
- Select the version that matches your operating system—Windows, Linux, or macOS are all supported.
- Click the download button and install IDE
Step 2: Installing Python in VSCode
- Look for the Extensions icon on the left-hand sidebar—it looks like four squares with one square detached.
- Search for 'Python' and select the one published by Microsoft.
- Click 'Install' and give it a moment to set up.
Step 3: Writing Your First Python Code
- With the Python extension installed, you can now write Python code.
- Open a new file, save it with the
.py
extension, and start typing your Python program. - You can run your code directly in VSCode. Just hit the green play button on the top right or press
F5
.
That’s it! You’ve set up your IDE, and you’re ready to dive into Python
programming.
python --version
Python 3.8.7
The print()
function is used in Python
in order to send data to the console. This is the primary way to output data from your program to the user.
In order to see the printed statement, you have to run the code, otherwise it won't be executed and there will be nothing inside the console.
print("We are learning Python!")
Create a file main.py
, save it in VScode (using shortcut Ctrl + s) or for Mac users (Cmd +s) and run the following command
python main.py
We are learning Python!
NOTE: You can use the single quotes and the output will remain the same.
print('We are learning Python!') == print("We are learning Python!")
The print()
command allows you to specify multiple arguments , in which case they must be separated by commas. If you leave out commas between arguments, Python will treat it as a syntax error.
print("I", "will" "become", "a" "software", "engineer")
I will become a software engineer!
Each subsequent print()
will create output the message on the next line
print("Hello")
print("World")
print("!")
Hello
World
!
The print()
function with an empty argument list simply inserts a new empty line.
print("What a lovely day!")
print()
print("Naah, I am too lazy to work, let's go to pub!")
What a lovely day!
Naah, I am too lazy to work, let's go to pub!
The print()
function in Python
has optional arguments sep
and end
which offer more control over the formatting of the output.
Argument | Purporse |
---|---|
sep | Specifies the separator between the values. By default, it is a space . |
end | Specifies what to print at the end . By default, it is a newline character (\n) . |
# Case #1 -> dash symbol is added between all string we pass into print()
print("There", "are", "5", "apples", sep="-")
# Case #2 -> instead of printing ``world!`` on the new (separate) we print it within one line
print("Hello", end=" ")
print("world!")
# Case #3 separate all worlds with a coma and add `and more` to the sentence
print("Python", "Java", "C++", sep=", ", end=" ")
print("and more!")
# Case #1
There-are-5-apples
# Case #2
Hello world!
# Case #3
Python, Java, C++, and more!
In Python, certain characters can be 'escaped' to achieve special formatting in strings.
Escape Sequence | Meaning |
---|---|
\n |
Newline - moves to the next line |
\t |
Horizontal Tab - adds a tab space |
\\ |
Backslash - to use a backslash itself |
\' |
Single Quote |
\" |
Double Quote |
print("This is a line.\nAnd this is another line.")
print("Name:\tJohn")
print("Path to the folder: C:\\Users\\John")
This is a line.
And this is another line.
Name: John
Path to the folder: C:\Users\John
The main goal as a software engineer is to make an
interactive
application which is user friendly and matches the highest standarts in the world of programming.
The input()
function in Python
allows your program to collect data entered by the user. This function waits for the user to type something into the console and then press Enter [↵]
.
It treats the incoming data as a string
(str
) and can be stored in a variable for further use.
In Python
, declaring variables is pretty straightforward, you just need to assign a value to a variable with the equals sign (=)
print("Hello, what is your name?")
# At this stage the programm is awaiting the input from user which we store in the variable called ``name`` and we can use it later
name = input()
print('Hello,', name, "it is nice to see you!")
In the example above we can see that the programm is executed line by line, because Python
is an interpretted language and it is very important to understand, that before executing the line Hello <name>, it is nice to see you!
it freezes, until the user is prompted to input their name
Hello, what is your name?
>> (Adam)
Hello Adam, it is nice to see you!
- Use only letters
(a-z, A-Z)
,digits
, andunderscores (_)
. - A variable name cannot start with a digit.
- The name must ideally reflect its purpose.
- Remember, Python is case-sensitive:
name
andName
are different variables. - The convention is to use
lower_case_with_underscores
.
Objective: Write a program that asks for the user's name and favorite color, then prints a personalized greeting that includes their name and favorite color.
Input:
- User's name
- User's favorite color
Output:
- A personalized greeting that includes the name and favorite color.
Objective: Create a program that asks for the user's adress, the item they are purchasing, and the cost. Then, print a summary of their order.
Input:
- User's adress
- Item name
- Item cost
Output:
- A summary of the user's order, including their adress, the item, and the cost.
Objective: Prompt the user to input what they learned today.
Input:
- Something you learned today.
Output:
- A reflection statement.
Check your answers by viewing the source of this markdown file!
What is the main purpose of programming?
A) To create documents and presentations.
B) To instruct the computer to perform tasks.
C) To browse the internet.
D) To play computer games.
Which statement about Python is true?
A) Python is only good for web development.
B) Python is a high-level programming language that is easy to learn.
C) Python cannot be used for data analysis.
D) Python programs can only run on Windows operating systems.
What is an IDE in the context of programming?
A) A set of rules that govern the syntax of a programming language.
B) A program that provides facilities like code editing and debugging to programmers.
C) A type of computer specially made for coding.
D) An internet service that speeds up your code.
Which of the following is a common use of Python?
A) Cooking recipes automation.
B) Changing the weather.
C) Web development and data science.
D) Time travel.
After writing a Python script, what is the file extension you should save it with?
A) .txt
B) .xls
C) .py
D) .ppt
- Research the history of Python. When was it created and by whom? What is PEP?
- Find three examples of how Python is used in different industries. Look for specific use cases such as
web development
,data analysis
orAI
- Try some hotkeys in
Visual Studio Code
! Explore your IDE!
Objective: Write a Python program that asks for the name of a soccer team and then prints a cheer for that team.
Requirements: The program should take the name of the soccer team as input. It should then output the name of the team followed by the cheer "are the champions!". Example:
# Sample Input
Barcelona
# Sample Output
Barcelona is a champion!
Objective: Create a Python program that captures three lines of text, one at a time, and then prints them out in reverse order.
# Sample Input
I love
Python
so much
# Sample Output
I love
Python
so much
Objective: Write a Python program that takes in three separate lines of text and then prints them out in reverse order.
# Sample Input
I love
Python
so much
# Sample Output
so much
Python
I love