0% found this document useful (0 votes)
11 views35 pages

Chapter One Python Course

This document serves as an introduction to programming, focusing on Python as a high-level, interpreted language. It covers key concepts such as programming languages, syntax differences, and the use of functions, variables, and comments in Python. Additionally, it provides practical examples and assignments to help users practice their coding skills.

Uploaded by

fahiimacaptann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views35 pages

Chapter One Python Course

This document serves as an introduction to programming, focusing on Python as a high-level, interpreted language. It covers key concepts such as programming languages, syntax differences, and the use of functions, variables, and comments in Python. Additionally, it provides practical examples and assignments to help users practice their coding skills.

Uploaded by

fahiimacaptann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Python

Chapter one

Lec: Ahmed Saed Warsame


WHAT IS THE PROGRAMMING?
Programming is the process of writing instructions that computers can
understand and execute. These instructions, known as code, are written
using programming languages like Python, Java, or C++. At its core,
programming allows people to create software, websites, apps, and even
control hardware like robots or self-driving cars.
WHAT IS THE PROGRAMMING
LANGUAGE?
A programming language is a formal system used to communicate with
computers, enabling programmers to write code that a computer can
understand and execute. These languages are the foundation of software
development, allowing people to create applications, websites, and even
AI systems.
DIFFERENCE BETWEEN
PROGRAMMING LANGUAGE
Programming languages differ in various ways based on their design,
syntax, use cases, performance, and features. Here's a breakdown
of the key differences between programming languages
1. Syntax
 Refers to the structure and rules of a language.
 Python: Simple, readable syntax (e.g., print("Hello"))
 C++: More complex (e.g., std::cout << "Hello";)

2. Level (Low-Level vs. High-Level)


 Low-level: Closer to machine code (e.g., Assembly, C)
 High-level: Closer to human language (e.g., Python, JavaScript)
DIFFERENCE BETWEEN
PROGRAMMING LANGUAGE
3. Compilation vs. Interpretation
 Compiled languages (e.g., C++, Rust): Translated into machine code before running →
faster execution.
 Interpreted languages (e.g., Python, JavaScript): Run line-by-line by an interpreter →
slower, but easier to debug.

4. Use Cases
 Web Development: JavaScript, PHP, Ruby
 System Programming: C, Rust
 Mobile Apps: Kotlin (Android), Swift (iOS)
 Data Science & AI: Python, R
 Game Development: C++, C#
WHAT IS THE PYTHON?
Python is a high-level, interpreted programming language known for its
simplicity and readability. It was created by Guido van Rossum and first
released in 1991.
KEY FEATURES OF PYTHON
Easy to learn and use: Simple, clean syntax that’s close to English.
Interpreted: Code runs line-by-line without needing to compile.
Dynamically typed: No need to declare variable types explicitly.
Versatile: Used in web development, data science, AI, automation,
scripting, and more.
Large standard library: Comes with many modules to do a lot of tasks out-
of-the-box.
Cross-platform: Runs on Windows, macOS, Linux, etc
POPULAR USES OF PYTHON:
Data science & machine learning: Libraries like pandas, NumPy,
TensorFlow.
Automation & scripting: Automate repetitive tasks.
Game development: Libraries like Pygame.
Education: Widely used to teach programming because of its simplicity.
Desktop Application(Tkinter).
TEXT EDITOR
Lightweight programs mainly for writing and editing code or text. Usually
don’t have built-in compilers or debuggers. Can be extended with plugins
to add more features
Examples:
 Notepad++ — Simple, Windows-based text editor with syntax highlighting.
 Sublime Text — Fast, extensible, popular among developers.
 Vim — Powerful, keyboard-driven editor, widely used in terminals
IDE STANDS FOR
INTEGRATED DEVELOPMENT
ENVIRONMENT.
It’s a software application that provides developers with a set of tools
to write, test, and debug code efficiently in one place

Feature Description
A text editor with features like
Code Editor syntax highlighting, auto-
completion, and formatting.
Translates your code into
Compiler/Interpreter
machine code so it can run.
Helps find and fix errors in your
Debugger code by inspecting the flow and
variables during execution.
Tools to automate repetitive
Build Automation Tools tasks like compiling and running
code.
Integration with systems like Git
Version Control
to track changes to your code.
EXAMPLES OF IDE

Visual Studio Code (VS Code) — Lightweight but with many IDE
features through extensions.
PyCharm — Specialized IDE for Python development.
IntelliJ IDEA — Popular for Java and Kotlin.
Eclipse — Used mainly for Java and C++.
Android Studio — Official IDE for Android app development.
Visual Studio — Powerful IDE mainly for .NET and C++.
CREATING CODE WITH
PYTHON
VS Code is a text editor. In addition to editing text, you can visually browse files and run text-
based commands at a terminal.
In the terminal, you can execute code hello.py to start coding.
In the text editor above, you can type print("hello, world"). This is a famous canonical
program that nearly all coders write during their learning process.
In the terminal window, you can execute commands. To run this program, you are going to
need to move your cursor to the bottom of the screen, clicking in the terminal window. You
can now type a second command in the terminal window. Next to the dollar sign, type python
hello.py and press the enter key on your keyboard.
Recall that computers really only understand zeros and ones. Therefore, when you run python
hello.py, Python will interpret the text that you created in hello.py and translate it into the
zeros and ones that the computer can understand.
The result of running the python hello.py program is hello, world.
FUNCTIONS
Functions are verbs or actions that the computer or computer language will
already know how to perform.
In your hello.py program, the print function knows how to print to the
terminal window.
The print function takes arguments. In this case, "hello, world" are the
arguments that the print function takes.
BUGS
Bugs are a natural part of coding. These are mistakes, problems for you to
solve! Don’t get discouraged! This is part of the process of becoming a great
programmer.
Imagine that in our hello.py program we accidentally typed print("hello,
world", forgetting the final ) required by the print function. If you make this
mistake, the interpreter will output an error in the terminal window!
Error messages can often inform you of your mistakes and provide clues on
how to fix them. However, there will be many times when the interpreter is
not this helpful.
BUGS
Bugs are a natural part of coding. These are mistakes, problems for you to
solve! Don’t get discouraged! This is part of the process of becoming a great
programmer.
Imagine that in our hello.py program we accidentally typed print("hello,
world", forgetting the final ) required by the print function. If you make this
mistake, the interpreter will output an error in the terminal window!
Error messages can often inform you of your mistakes and provide clues on
how to fix them. However, there will be many times when the interpreter is
not this helpful.
IMPROVING YOUR FIRST
PYTHON PROGRAM
We can personalize your first Python program.
In our text editor in hello.py we can add another function. input is a function
that takes a prompt as an argument. We can edit our code to say

Input(“What is your name?”);


Print(“hello , world”)


This edit alone, however, will not allow your program to output what your
user inputs. For that, we will need to introduce you to variables
VARIABLES
A variable is just a container for a value within your own program.
In your program, you can introduce your own variable in your program by
editing it to read.

Name = Input(“What is your name?”);


Print(“hello , world”)

Notice that this equal = sign in the middle of name = input("What's your
name? ") has a special role in programming. This equal sign literally assigns
what is on the right to what is on the left. Therefore, the value returned by
input("What's your name? ") is assigned to name.
VARIABLES
End attributes

Name = Input(“What is your name?”)


Print(“hello “ End=“”)
Print(Name)

Name = Input(“What is your name?”)


Print(f“hello {name}“)
COMMENTS
Comments are a way for programmers to track what they are doing in their
programs and even inform others about their intentions for a block of code. In
short, they are notes for yourself and others who will see your code!
You can add comments to your program to be able to see what it is that your
program is doing. You might edit your code as follows:
COMMENTS
#ask a user his or her name
Name = input(“what is your name?”)
Print(“hello”)
Print(name)
PSEUDOCODE
Pseudocode is an important type of comment that becomes a special type of
to-do list, especially when you don’t understand how to accomplish a coding
task. For example, in your code, you might edit your code to say:

# Ask the user for their name


name = input("What's your name? ")
# Print hello
print("hello,")
# Print the name inputted
print(name)
FURTHER IMPROVING
YOUR FIRST PYTHON
# PROGRAM
Ask the user for their name
name = input("What's your name? ")
# Print hello and the inputted name
print("hello, " + name)

# Ask the user for their name


name = input("What's your name? ")
# Print hello and the inputted name
print("hello,", name)
INPUT
You should never expect your user to cooperate as intended. Therefore, you
will need to ensure that the input of your user is corrected or checked.
It turns out that built into strings is the ability to remove whitespace from a
string.
By utilizing the strip method on name (for example, name = name.strip()),
you will remove any whitespace from the left and right of the user’s input. You
can modify your code to be:
INPUT
You should never expect your user to cooperate as intended. Therefore, you
will need to ensure that the input of your user is corrected or checked.
It turns out that built into strings is the ability to remove whitespace from a
string.
By utilizing the strip method on name (for example, name = name.strip()),
you will remove any whitespace from the left and right of the user’s input. You
can modify your code to be:
INTEGERS OR INT
n Python, an integer is referred to as an int.
In the world of mathematics, we are familiar with +, -, *, /, and %
operators. That last operator % or modulo operator may not be very
familiar to you.
You don’t have to use the text editor window to run Python code.
Down in your terminal, you can run python alone. You will be
presented with >>> in the terminal window. You can then run live,
interactive code. You could type 1+1, and it will run that calculation.
This mode will not commonly be used during this course.
Opening up VS Code again, we can type code calculator.py in the
terminal. This will create a new file in which we will create our
PYTHON CODE
x=1
y=2
z=x+y
print(z)
FLOAT BASICS
A floating point value is a real number that has a decimal point in it,
such as 0.52.
You can change your code to support floats as follows:

Code
x = float(input("What's x? "))
y = float(input("What's y? "))
print(x + y)
This change allows your user to enter 1.2 and 3.4 to present a total of
4.6.
EXAMPLE USING ROUND
METHOD
# Get the user's input
x = float(input("What's x? "))
y = float(input("What's y? "))

# Create a rounded result


z = round(x + y)

# Print the result


print(z)
DEF
Wouldn’t it be nice to create our own functions?
Let’s bring back our final code of hello.py by typing code hello.py
into the terminal window. Your starting code should look as follows:

# Ask the user for their name, remove whitespace from the str and capitalize the
first letter of each word
name = input("What's your name? ").strip().title()

# Print the output


print(f"hello, {name}")
EXAMPLE
def hello():
print("hello")

Name = input("What's your name? ")


hello()
print(name)
FUNCTION TAKING INPUT
# Create our own function
def hello(to):
print("hello,", to)

# Output using our own function


name = input("What's your name? ")
hello(name)
Here, in the first lines, you are creating your hello function. This
time, however, you are telling the interpreter that this function
takes a single parameter: a variable called to. Therefore, when you
call hello(name) the computer passes name into the hello function
as to. This is how we pass values into functions. Very useful!
Running python hello.py in the terminal window, you’ll see that the
output is much closer to our ideal presented earlier in this lecture.
ASSIGNMENT ONE
1.ask I user for his / her nama and when she/he born
2. your program should tell the age of the user
ASSIGENMENT TWO
1. Ask user for his/her name ,age,city
2. Your program should print this following sentances
3. My name is _____ . I am ____years old. I live in _____city.
ASSIGNMENT THREE
Make a function to calculate discount the constant discount is 0.75
Use def keyword.

You might also like