0% found this document useful (0 votes)
3 views

Basic Programming

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Basic Programming

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Basic Programming

Chapter 1: Overview about Programming and The python language

Some Definitions:

*Algorithm: conducting a sequence of specified actions that arranged in a


certain order, so that when we put the Input of the problem, we receive
The Output.

*Programming language: Is a file arranged in the best order defines and


instructs the computer to perform actions necessary to meet a previously
identified goal for humans like retrieving data, searching, solving problems,...

*Programming techniques:

+Procedural: (private opinion): divide the problem into other small problem,
solve all the problem leading to the final result (pure logic)

+Object-oriented: (private opinion): The problem relate to one/many specific


objects, which each objects have their own funtions and attributes. So, the
O-o will divide the problem to each objects, objects manage their own
functions and attributes, then they will exchange information with others
through Procedure ( a set of code)

*Steps for bulding a program

1.Survey 4. Check

2.Analyse 5. Transfer

3.Design 6.maintain

Chapter 2: Variables and Expressions

Definitions

* Variables: are like boxes where you store stuff (like numbers or
words).

A variable will have a name and may contain a value; Assignment:


“=”

Example of what is call a “variable”:


Variable naming rules:

*Operators:

-Priority from high to low


“=” Lowest

* Expressions: are like instructions or recipes that mix things


together (like numbers and variables) to give you a result.

-Mathematical operator precedence in expressions:

Example:

Value and Data Type:

*Value: A value is just a piece of information that Python works with. It could
be a number, a word, or even something more complex. (Ex: 18; “hello”;
3,14;...)

*Data Type: A data type is the kind of value you’re dealing with. In Python,
every value has a data type. It tells Python what kind of thing it is and how to
handle it.
-Some common data types:

+Integer: This is for whole numbers, like 1, 18, or -50.

+Float: This is for decimal numbers, like (PI=3,14; 0,5;...)

+String: This is for text, like "Hello!" or "Python is fun!". Strings are always
written inside quotes.

+Boolean: A Boolean is a type of data in Python that can only have one of two values:

 True (like "yes")


 False (like "no")

It’s kind of like a light switch: it can either be ON (True) or OFF (False). There's no in-
between.

Where do we use Booleans?

Booleans are super useful when we want to make decisions or check if something is right or
wrong.

For example:

 Is 5 greater than 3? Yes, so that would be True.


 Is your age equal to 100? No, so that would be False

Example in Context: Let’s say we’re building a simple program to decide if you’re old
enough to vote. In many countries, you need to be at least 18 years old to vote.

The answer is False

*Some basic funtions:

-Print function [print()]:

+It’s like a megaphone that allows your program to speak and show
information on the screen.
+You put whatever you want to display inside the parentheses ().

+You can also use print() to display the value of variables (those little boxes
that store information).

+You can combine text and variables in one print() statement. You just add
them together using the + symbol.

Ex:

+Instead of using the + symbol and converting numbers to strings, you can
use f-strings (formatted strings). They make it much easier to print
variables inside text.

Ex:

Printing Multiple items:


-Input function:[ input()]

+Is a built-in function in Python that lets you ask the user to type something.
It pauses the program, waits for the user to type, and then stores whatever
they type as text.

+Think of it like asking someone a question and waiting for their answer.
Whatever they type becomes the "answer" that you can use later in your
code.

+How it works (private opinion): use input mean you design space for the
user to put their input( a problem, a math, an information,...), the
programme will understand and then stored whatever they types as text.

+Input is always text . Whatever you type using input () comes in as a string
(text), even if you type a number.

+If you need to use numbers (for calculations, etc.), you must convert the
input from a string to a number using either int() (for whole numbers) or
float() (for decimals).

You might also like