Skip to content

Latest commit

 

History

History
485 lines (318 loc) · 15.4 KB

01.Introduction-to-programming.md

File metadata and controls

485 lines (318 loc) · 15.4 KB

Lesson 1: Introduction to Programming

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!

Content

  1. What is programming?
  2. Overview of Python
  3. Python installation
  4. IDE Installation (VSCode)
  5. print()
  6. input()
  7. Quiz: Introduction to Programming
  8. Homework

1. What is programming?

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.

1.1 What can you do with programming?

Talking of all opportunities which are opened to you after learning how programming works , you will be able to do the following things:

  1. Solve Problems: Programming can be used to model and solve complex problems in fields like finance, engineering, and medicine.

  2. Develop Software and Applications: From the operating system on your computer to the apps on your phone, programming is the backbone of software development.

  3. Create Websites: Web development involves programming both the visual front-end that users interact with and the back-end that processes data.

  4. 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.

  5. Analyze Data: With programming, you can process large sets of data to find patterns and insights, a practice commonly known as data science.

  6. Build Games: Game development is another avenue, where programming brings to life the mechanics, graphics, and interactivity of a game.

2. Overview of Python

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

2.1 Sample Programs

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

File:Instagram logo 2016.svg - Wikimedia Commons File:Pinterest-logo.png - Wikimedia Commons File:Spotify App Logo.svg - Wikipedia Brand - Reddit Youtube Logo - Free Vectors & PSDs to Download

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

Top 10 Programming Languages - 2023 Updated List - InvoZone

3. Python installation

For Windows Users

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 press Enter.
  • If Python is installed correctly, you should see the version number.

For macOS Users

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 type python --version and press Enter.
  • The version number should appear if the installation was successful.

4. IDE Installation (VSCode)

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.

Output

python --version
Python 3.8.7

5. print()

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.

Example

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

Output

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.

Example

print("I", "will" "become", "a" "software", "engineer")

Output

I will become a software engineer!

Each subsequent print() will create output the message on the next line

Example

print("Hello")
print("World")
print("!")

Output

Hello
World
!

5.1 print() with and without arguments

The print() function with an empty argument list simply inserts a new empty line.

Example

print("What a lovely day!")
print()
print("Naah, I am too lazy to work, let's go to pub!")

Output

What a lovely day!

Naah, I am too lazy to work, let's go to pub!

5.2 sep and end arguments

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).

Example

# 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!")

Output

# Case #1
There-are-5-apples

# Case #2 
Hello world!

# Case #3 
Python, Java, C++, and more!

5.3 Escaping characters

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

Example

print("This is a line.\nAnd this is another line.")
print("Name:\tJohn")
print("Path to the folder: C:\\Users\\John")

Output

This is a line.
And this is another line.
Name:   John
Path to the folder: C:\Users\John

6. input()

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 (=)

Example

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!")

Explanation

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

Output

Hello, what is your name?
>> (Adam)
Hello Adam, it is nice to see you!

6.2 Rules how to name variables

  • Use only letters (a-z, A-Z), digits, and underscores (_).
  • A variable name cannot start with a digit.
  • The name must ideally reflect its purpose.
  • Remember, Python is case-sensitive: name and Name are different variables.
  • The convention is to use lower_case_with_underscores.

6.3 Assignments

Assignment 1: Personalized Greeting

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.

Assignment 2: Order Summary

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.

Assignment 3: Daily Reflection

Objective: Prompt the user to input what they learned today.

Input:
- Something you learned today.

Output:
- A reflection statement.

7. Quiz: Introduction to Programming

Check your answers by viewing the source of this markdown file!

Question 1:

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.


Question 2:

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.


Question 3:

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.


Question 4:

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.


Question 5:

After writing a Python script, what is the file extension you should save it with?

A) .txt
B) .xls
C) .py
D) .ppt


8. Homework

Task 1: Investigate Python's History

  • Research the history of Python. When was it created and by whom? What is PEP?

Task 2: Real-World Python Applications

  • Find three examples of how Python is used in different industries. Look for specific use cases such as web development, data analysis or AI

Task 3: Discover IDE Features

  • Try some hotkeys in Visual Studio Code! Explore your IDE!

Task 4: My favourite football team

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!

Task 5: Repeat after me

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

Task 6: Reverse Echo

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