|
Pure Software code |
| |
Lebanon  | |
|
|
Python Pages -
1 2
3
4
5
6 |
|
|
|
1- |
Python Tutorial, Learn Python even ... |
|
|
|
1.1- Python for Everybody Course |
|
Teach yourself, Python for
Everybody |
Python for Everybody Course, Html
files - (11.6 MB zip file,
PythonForEverybodyCourse.zip),
download | |
|
0
Intro, Python for Everybody &
Installing | |
1 Why
to write Program
Python? | |
2
Variables, Expressions
... | |
|
|
|
|
|
5 Loops
and Iterations Structures.
| |
|
|
|
6
String Variables and Functions.
| |
7
Files, Open and Read
.. | |
|
|
|
|
9
Dictionary Data
Structures | |
|
|
|
|
|
|
|
14
Object-Oriented
Programming | |
|
|
|
15 Databases, the Structured Query
Language | |
|
| |
| |
Python
Tutorial,
Teach yourself Python |
|
|
|
|
|
|
1.2- How to Install Python on Windows |
|
Python is a high level
object-oriented, programming language. It has
built-in data structures, combined with dynamic
typing & binding which makes it an ideal
choice for rapid application development. Python
also offers support for modules and packages,
which allows system modularity and code reuse.
|
|
|
|
|
 |
Continue
|
How to
Install Python on Windows | |
|
|
1.2.1 |
Installing Python |
|
- Step 1
To
download and install Python visit the official
website of Python
http://www.python.org/downloads/ and choose your
version. We have chosen Python version 3.6.3 (or
Later)
- Step 2
Once the
download is complete, run the exe for install
Python. Now click on Install Now.
- Step 3
You can see
Python installing at this point.
- Step 4
When it
finishes, you can see a screen that says the
Setup was successful. Now click on "Close".
|
|
| | | |
|
|
|
|
1.3- The 12 BEST
Python IDE (Integrated
Development Environment), Python Editors
for Windows |
|
|
Python code editors are designed for the
developers to code and debug program
easily. Using these Python IDEs(Integrated
Development Environment), you can manage a
large codebase and achieve quick
deployment. |
|
|
 |
Continue
|
The 12
BEST Python IDE, Python Editors for Windows | |
|
|
1.3.1 |
The 12 BEST Python IDE, Python Editors
for Windows |
|
Developers can use these editors to create
desktop or web application. The Python
IDEs can also be used by DevOps engineers
for continuous Integration.
|
-
PyCharm
PayCharm is a cross-platform IDE used
for Python programming. It is one of the
best Python IDE editor that can be used
on Windows, macOS, and Linux. This
software contains API that can be used
by the developers to write their own
Python plugins so that they can extend
the basic functionalities.
- Kite
Kite is IDE for Python that
automatically completes multiple line
codes. This editor supports more than 16
languages. It helps you to code faster
with no hassle.
-
Spyder
Spyder is a scientific integrated
development environment written in
Python. This software is designed for
and by scientists who can integrate with
Matplotlib, SciPy, NumPy, Pandas, Cython,
IPython, SymPy, and other open-source
software. Spyder is available through
Anaconda (open-source distribution
system) distribution on Windows, macOS,
and Linux.
- IDLE
IDLE (Integrated Development and
Learning Environment) is a default
editor that comes with Python. It is one
of the best Python IDE software which
helps a beginner to learn Python easily.
IDLE software package is optional for
many Linux distributions. The tool can
be used on Windows, macOS, and Unix.
-
Sublime Text 3
Sublime Text 3 is a code editor which
supports many languages including
Python. It is one of the best Python
editor that has basic built-in support
for Python. Customization of Sublime
Text 3 is available for creating create
a full-fledged Python programming
environment. The editor supports OS X,
Windows, and Linux operating systems.
-
Visual Studio Code (2019)
Visual Studio Code (VS Code) is an
open-source environment developed by
Microsoft. It is one of the best Python
IDE for Windows that can be used for
Python development. Visual Studio Code
is based on Electron which is a
framework to deploy Node JS applications
for the computer running on the Blink
browser engine.
- Atom
Atom is a useful code editor tool
preferred by programmers due to its
simple interface compared to the other
editors. Atom users can submit packages
and them for the software.
-
Jupyter
Jupyter is a tool for people who have
just started with data science. It is
easy to use, interactive data science
IDE across many programming languages
that just not work as an editor, but
also as an educational tool or
presentation.
-
Pydev
PyDev is a third-party Python editor for
Eclipse. It is one of the best IDE for
Python which can be used in not only
Python but IronPython and Jython
development.
-
Thonny
Thonny is an IDE for learning and
teaching programming, specially designed
with the beginner Pythonista scripting
environment. It is developed at The
University of Tartu, which you can
download for free on the Bitbucket
repository for Windows, Linux, and Mac.
- Wing
Wing is a lightweight Python environment
which is designed to give you productive
development experience.
-
ActivePython
Increase software development data
science with a secure and supported
Python distribution. Active Python is
software consisting of the Python
implementation CPython and a set of
various extensions to facilitate
installation.
|
|
|
| | | |
|
|
|
|
1.4-
Python, How to Install pip |
|
|
PIP is
a package management system used to
install and manage software packages
written in Python. It stands for
“preferred installer program” or “Pip Installs Packages.”
PIP
for Python is a utility to
manage PyPI package installations from the
command line.
Note:
1-
If you have Python version 3.4 or later,
PIP is included by default
2-
If you are using an older version of Python
on Windows, you may need to install PIP.
You can easily install PIP on Windows by
downloading the installation package, opening the
command line, and launching the installer.
.
Example
how to install the anytree
module at Command Prompt
C:\Users\User> =
C:\Users\%UsenName%> |
 |
|
|
|
|
 |
Continue
|
PIP for
Python - This tutorial will show how to install
PIP on Windows, check its version, upgrade, and
configure. | |
|
Download, How To
Install PIP to Manage Python Packages On Windows - (225
KB zip file)
download
|
|
 |
|
|
Prerequisites
-
Computer running Windows or Windows
server
-
Access to the Command Prompt window
Before you start: Check if PIP is Already
Installed
PIP is automatically installed with Python
2.7.9+ and Python 3.4+ and it comes with
the virtualenv and pyvenv virtual
environments.
Before you install
PIP on Windows, check if PIP is
already installed.
1. Launch the command prompt window:
-
Press Windows
Key + X.
-
Click Run.
-
Type in cmd.exe and
hit enter.
Alternatively, type cmd in
the Windows search bar and click the
“Command Prompt” icon.
2. Type in the following command at the
command prompt:
top: 3100px;
If PIP responds, then PIP is installed.
Otherwise, there will be an error saying
the program could not be found.
Note:
C:\Users\Sofija Simic>
= C:\Users\%UsenName%>
Installing PIP On Windows
Follow the steps outlined below to install
PIP on Windows.
Step 1: Download PIP get-pip.py
Before installing PIP, download the get-pip.py
file.
1. Launch a command prompt if it isn't
already open. To do so, open the Windows
search bar, type cmd and
click on the icon.
2. Then, run the following command to
download the get-pip.py file:
Step 2: Installing PIP on Windows
To install PIP type in the
following:
If the file isn’t found, double-check the
path to the folder where you saved the
file. You can view the contents of your
current directory using the following command:
The dir command
returns a full listing of the contents of
a directory.
Step 3: Verify Installation
Once you’ve installed PIP, you can test
whether the installation has been
successful by typing the following:
top: 3100px;
If PIP has been installed, the program
runs, and you should see the location of
the software package and a list of
commands you can use with pip .
If you receive an error, repeat the
installation process.
Step 4: Add Pip to Windows Environment
Variables
To run PIP from any location, you need to
add it to Windows environment variables to
avoid getting the "not on PATH" error. To
do so, follow the steps outlined below:
-
Open the System
and Security window by
searching for it in the Control
Plane.
-
Navigate to System settings.
-
Then, select Advanced
system settings.
-
Open the Environment
Variables and
double-click on the Path variable
in the System
Variables.
-
Next, select New and
add the directory where you installed
PIP.
-
Click OK to
save the changes.
Step 5: Configuration
In Windows, the PIP configuration file
is %HOME%\pip\pip.ini.
There is also a legacy per-user
configuration file. The file is located
at %APPDATA%\pip\pip.ini .
You can set a custom path location for this
config file using the environment
variable PIP_CONFIG_FILE .
Upgrading PIP for Python on Windows
New versions of PIP are released
occasionally. These versions may improve
the functionality or be obligatory for
security purposes.
To check the current version of PIP,
run:
To upgrade PIP on Windows, enter the
following in the command prompt:
This command uninstalls the old version of
PIP and then installs the most current
version of PIP.
Downgrade PIP Version
Downgrading may be necessary if a new
version of PIP starts performing
undesirably. To downgrade PIP to a prior version,
specifying the version you want.
To downgrade PIP, use the syntax:
For example, to downgrade to version 18.1,
you would run:
You should now see the version of PIP that
you specified |
|
|
| | | |
|
|
|
|
|
2- |
Python
14 Samples Program |
|
|
2.1- Python Program to Find ASCII Value of
Character |
|
- In this program, you'll learn to find the
ASCII value of a character and display
it.
Using PyCham Compiler - (IDE), to compile
Python
project / file
- Source Code:
Download this
Source Code at python file - (0.6
MB txt file) download
|
Download this
Source Code at txt file - (1.01 MB
txt file) download
|
 |
Continue
|
Python Code,
Find ASCII
Value | |
|
|
|
# 1-
print print("Hello World") # 2-
print print("Goodbye") # 3- Program to
find the ASCII value of the given character #
Change this value for a different result #
Example c = 'p' # Uncomment to take character
from user c = input("Enter a
character(1character): ") # 4- print("The
ASCII character :" ) print(c) print("The
value of this character : "
) print(ord(c)) |
|
| | | |
|
- Output:
|
| | |
|
2.2- Python Program to display value of
try
operation |
|
- In this program, you'll learn to
display value of "try operation"
Using PyCham
Compiler - (IDE), to compile Python project /
file
- Source Code:
Download
this Source Code at python file -
(0.3 MB txt file) download |
Download this
Source Code at txt file - (1.01 MB
txt file) download |
 |
Continue
|
Python Code,
to display value
| |
|
|
|
#The
try block will generate a NameError, because x
is not
defined:
try: print(x) except
NameError: print("Variable x is not
defined") except: print("Something else
went wrong") |
|
| | | |
|
- Output :
Variable x is
not
defined | |
| | |
|
2.3- Python Program to display calendar of
given month of the year |
|
- In this program, you'll learn to
display calendar of given month of the year
.
Using PyCham Compiler - (IDE), to compile
Python
project / file
- Source Code:
Download
this Source Code at python file -
(0.3 MB txt file) download |
Download this
Source Code at txt file: calendar1.txt - (1.01 MB
txt file)
download |
 |
Continue
|
Python Code,
to display
calendar | |
|
|
|
#
Python program to display calendar of given
month of the year # import module import
calendar yy = 2019 mm = 11 # To ask
month and year from the user # yy =
int(input("Enter year: ")) # mm =
int(input("Enter month: ")) # display the
calendar print(calendar.month(yy,
mm)) |
|
| | |
- Output :
| | |
|
2.4- Python Program to display list of
Values. |
|
- In this program, you'll learn to
display list of Values.
Using PyCham Compiler
- (IDE), to compile Python project /
file
- Source Code:
Download this
Source Code at python file: Pfile-proglist2.py -
(2.45MB py file)
download
|
 |
Continue
|
Python Code,
to display list of
Values | |
|
|
|
#Home
# print("Hello, World!") - form not
available
b1="""Hello,
World!"""
print(b1)
#Syntax
#if 5 > 2:
# print("Five is greater than two!") - form
not available
b2="""Five is greater
than two!"""
print(b2)
#Comments
#print("Cheers, Mate!") - form not
available
b3="""Cheers,
Mate!"""
print(b3)
#variable
x01 = 4 #
x is of type int
print(x01)
x02 =
"Sally" # x is now of type str
print(x02)
x1 =
"John"
# is the same as
x1 =
'John'
print(x1)
x2, y, z
= "Orange", "Banana", "Cherry"
print(x2)
print(y)
print(z)
#Data Type
x3 =
str("Hello World")
print(x3)
x4 =
int(20)
print(x4)
x5 =
float(20.5)
print(x5)
x6 =
complex(1j)
print(x6)
x7 =
list(("apple", "banana",
"cherry"))
print(x7)
x8 =
tuple(("apple", "banana",
"cherry"))
print(x8)
x9 =
range(6)
print(x9)
x10 =
dict(name="John", age=36)
print(x10)
x11 =
set(("apple", "banana",
"cherry"))
print(x11)
x12 =
frozenset(("apple", "banana",
"cherry"))
print(x12)
x13 =
bool(5)
print(x13)
x14 =
bytes(5)
print(x14)
x15 =
bytearray(5)
print(x15)
x16 =
memoryview(bytes(5))
print(x16)
#numbers
xx = 1 #
int
yy = 2.8
# float
zz = 1j #
complex
#convert from int to float:
aa =
float(xx)
#convert from float to int:
bb =
int(yy)
#convert from int to complex:
cc =
complex(zz)
print(aa)
print(bb)
print(cc)
print(type(aa))
print(type(bb))
print(type(cc)) |
|
| | | |
|
- Output:
|
| | |
|
2.5- Python Program to display list
of Values of Operations. |
|
- In this program, you'll learn to
display list of Values of Operations.
Using
PyCham Compiler - (IDE), to compile Python project /
file
- Source Code:
Download this
Source Code at python file: Pfile2-proglist2.py - (2.45
MB py file)
download
|
 |
Continue
|
Python Code,
to display list of Values of
Operations | |
|
|
|
#casting x = int(1) # x will be 1
y = int(2.8) # y will be 2 z =
int("3") # z will be
3 print(x) print(y) print(z)
x1
= float(1) # x will be 1.0 y1 = float(2.8) #
y will be 2.8 z1 = float("3") # z will be
3.0 w1 = float("4.2") # w will be
4.2 print(x1) print(y1) print(z1) print(w1)
x2
= str("s1") # x will be 's1' y2 = str(2) # y
will be '2' z2 = str(3.0) # z will be
'3.0' print(x2) print(y2) print(z2)
#string a
= """Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua.""" print(a)
#boolean x4 =
"Hello" y4 =
15 print(bool(x4)) print(bool(y4))
#operators #+
Addition x + y #- Subtraction x - y #*
Multiplication x * y #/ Division x / y #%
Modulus x % y #** Exponentiation x **
y #// Floor division x // y
#= x = 5 x
= 5 #+= x += 3 x = x + 3 #-= x -= 3 x = x
- 3 #*= x *= 3 x = x * 3 #/= x /= 3 x = x
/ 3 #%= x %= 3 x = x % 3 #//= x //= 3 x =
x // 3 #**= x **= 3 x = x ** 3 #&= x
&= 3 x = x & 3 #|= x |= 3 x = x |
3 #^= x ^= 3 x = x ^ 3 #>>= x
>>= 3 x = x >> 3 #<<= x
<<= 3 x = x << 3
#== Equal x
== y #!= Not equal x != y #> Greater
than x > y #< Less than x <
y #>= Greater than or equal to x >=
y #<= Less than or equal to x <=
y
#and Returns True if both statements
are true x < 5 and x < 10 #or Returns
True if one of the statements is true x < 5
or x < 4 #not Reverse the result, returns
False if the result is true not(x < 5 and x
< 10)
#is Returns true if both
variables are the same object x is y #is not
Returns true if both variables are not the same
objec
#in Returns True if a sequence with
the specified value is present in the object x
in y #not in Returns True if a sequence with
the specified value is not present in the
object
#& AND Sets each bit to 1 if
both bits are 1 #| OR Sets each bit to 1 if
one of two bits is 1 # ^ XOR Sets each bit to
1 if only one of two bits is 1 #~ NOT Inverts
all the bits #<< Zero fill left shift
Shift left by pushing zeros in from the right
and let the leftmost bits fall off #>>
Signed right shift Shift right by pushing copies
of the leftmost bit in from the left, and let
the rightmost bits fall off
fruits =
["apple", "banana"] #if
"apple" #fruits # print("Yes, apple is a
fruit!") - form not available bb="""Yes,
apple is a
fruit!""" print(bb)
#list thislist
= ["apple", "banana", "cherry", "orange",
"kiwi", "melon",
"mango"] print(thislist[-1]) print(thislist[1]) print(thislist[-4:-1]) thislist[1]
=
"blackcurrant" print(thislist)
|
|
| | | |
|
- Output:
1 2 3 1.0 2.8 3.0 4.2 s1 2 3.0 Lorem
ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. True True Yes,
apple is a
fruit! mango banana ['orange', 'kiwi',
'melon'] ['apple', 'blackcurrant', 'cherry',
'orange', 'kiwi', 'melon',
'mango'] | |
| | |
|
2.6- Python Program to display list of
Values of Formats |
|
- In this program, you'll learn to
display list of Values of Formats
Using
PyCham Compiler - (IDE), to compile Python project /
file
- Source Code:
Download this
Source Code at python file - (1.26
MB txt file) download
|
Download this
Source Code at txt file - (2.37 MB
txt file) download |
 |
Continue
|
Python Code,
to display list of Values of
Formats | |
|
|
|
class
Car:
def __init__(self,
speed=0): self.speed = speed self.odometer
= 0 self.time = 0
def
say_state(self): print("I'm going {}
kph!".format(self.speed))
def
accelerate(self): self.speed += 5
def
brake(self): self.speed -= 5
def
step(self): self.odometer +=
self.speed self.time += 1
def
average_speed(self): if self.time !=
0: return self.odometer /
self.time else: pass
if
__name__ == '__main__':
my_car =
Car() print("I'm a car!") while
True: action = input("What should I do? type
[A]=Accelerate, [B]=Brake, [O]=show dometer, or
[S]=show average Speed?").upper()
if
action not in 'ABOS' or len(action) !=
1: print("I don't know how to do
that")
continue
if action ==
'A': my_car.accelerate()
elif action
== 'B': my_car.brake()
elif action ==
'O': print("The car has driven {}
kilometers".format(my_car.odometer))
elif
action == 'S': print("The car's average speed
was {}
kph".format(my_car.average_speed())) my_car.step()
my_car.say_state() |
|
| | | |
|
- Output:
I'm a
car!
What should I do? type
[A]=Accelerate, [B]=Brake, [O]=dometer, or
[S]=average Speed?A I'm going 5
kph!
What should I do? type
[A]=Accelerate, [B]=Brake, [O]=dometer, or
[S]=average Speed?S The car's average speed
was 5.0 kph I'm going 5 kph!
What
should I do? type [A]=Accelerate, [B]=Brake,
[O]=dometer, or [S]=average Speed?0 I don't
know how to do that
What should I do?
type [A]=Accelerate, [B]=Brake, [O]=dometer, or
[S]=average Speed?5 I don't know how to do
that
What should I do? type
[A]=Accelerate, [B]=Brake, [O]=dometer, or
[S]=average Speed?
... | |
| | |
|
2.7-
Python
Program to Merge Mails |
|
- In this program, you'll learn to merge
mails into one.
* String
Methods * Python File I/O When we
want to send the same invitations to many
people, the body of the mail does not change.
Only the name (and maybe address) needs to be
changed.
Mail merge is a process of doing
this. Instead of writing each mail separately,
we have a template for body of the mail and a
list of names that we merge together to form all
the mails.
- Source Code:
Download this
Source Code at python file - (0.8
MB txt file) download |
Download this
Source Code at txt file - (1.22 MB
txt file) download |
 |
Continue
|
Python Code,
to Merge
Mails | |
|
|
|
#
Python program to mail merger # Names are in
the file names.txt # Body of the mail is in
body.txt # open names.txt for reading with
open("C:\_NF/names.txt",'r',encoding = 'utf-8')
as names_file: # open body.txt for
reading with
open("C:\_NF/body.txt",'r',encoding = 'utf-8')
as body_file:
# read entire content of
the body body = body_file.read() # iterate
over names for name in names_file: mail =
"Hello "+name+body # write the mails to
individual files with
open(name.strip()+".txt",'w',encoding = 'utf-8')
as mail_file: mail_file.write(mail) |
|
| | | |
|
- Output:
Process
finished with exit code 0 (0
err0r) ---------------------------------------------------------- For
this program, we have written all the names in
separate lines in the file "names.txt". The body
is in the "body.txt" file.
We open both
the files in reading mode and iterate over each
name using a for loop. A new file with the name
"[name].txt" is created, where name is the name
of that person.
We use strip() method to
clean up leading and trailing whitespaces
(reading a line from the file also reads the
newline '\n' character). Finally, we write the
content of the mail into this file using the
write()
method. | |
| | |
|
2.8- Python Program to display
values of data |
|
- In this program, you'll learn and
display values of data.
Using PyCham Compiler
- (IDE), to compile Python project /
file
- Source Code:
Download
this Source Code at python file:
file1-progKlm.py -
(1.39 MB txt file) download
|
 |
Continue
|
Python Code,
to display values of
data | |
|
|
|
#Home
# print("Hello, World!") - form not
available
b1="""Hello,
World!"""
print(b1)
#Syntax
#if 5 > 2:
# print("Five is greater than two!") - form
not available
b2="""Five is greater
than two!"""
print(b2)
#Comments
#print("Cheers, Mate!") - form not
available
b3="""Cheers,
Mate!"""
print(b3)
#variable
x01 = 4 #
x is of type int
print(x01)
x02 =
"Sally" # x is now of type str
print(x02)
x1 =
"John"
# is the same as
x1 =
'John'
print(x1)
x2, y, z
= "Orange", "Banana", "Cherry"
print(x2)
print(y)
print(z)
#Data Type
x3 =
str("Hello World")
print(x3)
x4 =
int(20)
print(x4)
x5 =
float(20.5)
print(x5)
x6 =
complex(1j)
print(x6)
x7 =
list(("apple", "banana",
"cherry"))
print(x7)
x8 =
tuple(("apple", "banana",
"cherry"))
print(x8)
x9 =
range(6)
print(x9)
x10 =
dict(name="John", age=36)
print(x10)
x11 =
set(("apple", "banana",
"cherry"))
print(x11)
x12 =
frozenset(("apple", "banana",
"cherry"))
print(x12)
x13 =
bool(5)
print(x13)
x14 =
bytes(5)
print(x14)
x15 =
bytearray(5)
print(x15)
x16 =
memoryview(bytes(5))
print(x16)
#numbers
xx = 1 #
int
yy = 2.8
# float
zz = 1j #
complex
#convert from int to float:
aa =
float(xx)
#convert from float to int:
bb =
int(yy)
#convert from int to complex:
cc =
complex(zz)
print(aa)
print(bb)
print(cc)
print(type(aa))
print(type(bb))
print(type(cc)) |
|
| | | |
- Output:
|
| | |
|
2.9- Python Program to
display different ways to test
multiple. |
|
- In this program, you'll learn to
display different ways to test
multiple.
Using PyCham Compiler - (IDE), to compile
Python project / file
- Source Code:
Download this
Source Code at txt file - (0.396 MB
txt file) download |
 |
Continue
|
Python Code,
to display different
ways | |
|
|
|
#
Different ways to test multiple # flags at
once in Python x, y, z = 0, 1, 0
if x
== 1 or y == 1 or z ==
1: print('1-passed')
if 1 in (x, y,
z): print('2-passed')
# These only
test for truthiness: if x or y or
z: print('3-passed')
if any((x, y,
z)): print('4-passed') |
|
| | | |
- Output:
|
| | |
|
2.10- Python Program to
display Math Function |
|
- In this program, you'll learn to
display Math Function
Using PyCham
Compiler - (IDE), to compile Python project / file
- Source Code:
Download this
Source Code at Python file (Py_sapp.py) - (1
KB
Python file)
download |
 |
Continue
|
Python Code,
to display Math Function | |
|
|
|
import
math
def
is_positive_integer(x):
try:
x
=
float(x)
except
ValueError:
return
False
else:
if
x.is_integer()
and
x
> 0:
return
True
else:
return
False
def
trailing_zeros(num):
if
is_positive_integer(num):
#
The above function call has done all the sanity
checks for us
#
so we can just convert this into an integer here
num =
int(num)
k =
math.floor(math.log(num,
5))
zeros = 0
for i
in
range(1, k
+ 1):
zeros = zeros +
math.floor(num/math.pow(5,
i))
return
zeros
else:
print( "Factorial
of a non-positive non-integer is undefined")
if
__name__ ==
"__main__":
fact_num = input(
"Enter the number whose factorial's trailing
zeros you want to find: "
)
num_zeros = trailing_zeros(fact_num)
print( "Number
of trailing zeros: {0}".format(num_zeros))
|
|
| | | |
- Output:
Step 1 |
|
step 2 | |
| | |
|
2.11- Python Lambda Functions |
|
- In this program, you'll learn to
display Lambda Functions
What is Lambda?
Lambdas, also known as anonymous functions, are
small, restricted functions which do not need a
name (i.e., an identifier). Lambda functions
were first introduced to the field of
mathematics by Alonzo Church in the 1930s.
7 Lambda Functions:
#1
#2- What a lambda returns-1
#3- What a lambda returns-2
#4- lambdas in filter()
#5- lambdas in map()
#6- lambdas in reduce[vV2][J3]
#7- REGULAR FUNCTION Using PyCham
Compiler - (IDE), to compile Python project / file
- Source Code:
Download this
Source Code at Python file (Py_lambada1.py) - (2
KB
Python file)
download |
 |
Continue
|
Python Code,
Python Lambda Functions | |
|
|
|
# Lambda Functions
print ("
7 Lambda functions
")
#1
adder
=
lambda
x,
y:
x
+
y
print ( "#1-
", adder
(1, 2))
#2- What a lambda returns
string= 'some
kind of a useless lambda'
print( "#2-
",
lambda
string :
print(string))
#3- What a lambda returns #2
x= "some
kind of a useless lambda"
( lambda
x
: print("#3-
",
x))(x)
#4- lambdas in filter()
sequences = [10,2,8,7,5,4,3,11,0, 1]
filtered_result =
filter (lambda
x:
x
> 4, sequences)
print( "#4-
",
list(filtered_result))
#5- lambdas in map()
sequences = [10,2,8,7,5,4,3,11,0, 1]
filtered_result =
map (lambda
x:
x*x,
sequences)
print( "#5-
",
list(filtered_result))
#6- lambdas in reduce[vV2][J3]()
from
functools
import
reduce
sequences = [1,2,3,4,5]
product = reduce ( lambda
x,
y:
x*y,
sequences)
print( "#6-
",
product)
#7- REGULAR FUNCTION
def
guru(
funct, *args
):
funct( *args
)
def
printer_one(
arg ):
return
print ("#7-
",
arg)
def
printer_two(
arg ):
print( arg)
#CALL A REGULAR FUNCTION
guru( printer_one,
'printer 1 REGULAR CALL'
)
guru( printer_two,
'printer 2 REGULAR CALL \n'
)
#CALL A REGULAR FUNCTION THRU A LAMBDA
guru( lambda:
printer_one('printer
1 LAMBDA CALL'))
guru( lambda:
printer_two('printer
2 LAMBDA CALL'))
|
|
| | | |
- Output - 7 Lambda Functions:
 |
7 Lambda Functions:
#1
#2- What a lambda returns-1
#3- What a lambda returns-2
#4- lambdas in filter()
#5- lambdas in map()
#6- lambdas in reduce[vV2][J3]
#7- REGULAR FUNCTION |
|
| | |
|
2.12- Python Program to display
functions of Matplotlib. Matplotlib is a plotting
library for the Python |
web
adrress of functions of Matplotlib. Matplotlib
is a plotting library for the Python:
https://matplotlib.org/gallery/index.html
|
2.12.1- Python Program
to display function of Matplotlib.
Matplotlib is a plotting library for the Python
-1 |
|
- In this
program, you'll learn to display function of
Matplotlib.
Matplotlib is a plotting library for the Python
programming language and its numerical
mathematics extension NumPy. It provides an
object-oriented API for embedding plots into
applications using general-purpose GUI
toolkits
project
file: Py-test.pyproj Using Microsoft
Visual studio 2019 Compiler - (IDE), to compile
Python
project / file
- Source Code:
Download this
Source Code at txt file - (0.376 MB
txt file) download |
 |
Continue
|
Python Code,
to display function of Matplotlib
-1 | |
|
|
|
# Matplotlib
is a plotting library for the Python programming
language for creating static,
# animated, and interactive visualizations in
Python
from
math import radians
import
numpy as np # installed with
matplotlib
import
matplotlib.pyplot as plt
def
main():
x = np.arange(0, radians(1800),
radians(12))
plt.plot(x, np.cos(x), 'b')
plt.show()
main() |
|
| | | |
|
- Output:
|
| | |
|
2.12.2- Python Program, Python Data
Analysis, Plotting emission graph for
country. (Matplotlib is a plotting library) |
|
-
Name: Python Data Analysis
-
Purpose: Plotting emission graph for country
-
Algorithm:
Step 1: Take the input from user to visualize
data
Step 2: Getting the index of Country and passing
it to plot function, Setting the Title and Label
of Plot
Matplotlib is a plotting library for the Python
programming language and its numerical
mathematics extension NumPy. It provides an
object-oriented API for embedding plots into
applications using general-purpose GUI
toolkits
-
Using Microsoft
Visual studio 2019 Compiler - (IDE), to compile
Python
project / file
- Download the visual
studio 2019 (python) [stores
Emissions.csv
and py-4za-day3.py] -
(25
KB zip file)
download
|
 |
- Source Code:
1- |
(Emissions.csv
- Excel file store Data - CO2 statistics (1997
to 2010) of 195 Countries)
-
Download
this Excel file, 34 KB |
|
|
2- |
Download this
Source Code at Python file - py-4za-day3.py - (8
KB
Python file)
download
|
|
|
 |
Continue
|
Python Code,
Python Data Analysis, Plotting emission graph
for country. (Matplotlib is a plotting library) | |
|
|
|
""" Name: Python Data Analysis
Purpose: Plotting emission graph for country
Algorithm:
Step 1: Take the input from user to visualize
data
Step 2: Getting the index of Country and
passing it to plot function, Setting the Title
and Label of Plot
"""
import
matplotlib.pyplot
as
plt
print( "A
Simple Data Analysis Program")
print()
emission_dict = {}
#
Emissions.csv - Excel file store Data - CO2
statistics (1997 to 2010) of 195 Countries
with
open('Emissions.csv',
'r')
as file:
for data
in
file.read().split('\n'):
emission_dict.update({data.split( ',')[0]:
data.split(',')[1:]})
print( "All
data from Emissions.csv has been read into a
dictionary.",
end="\n\n")
input_year = input( "Select
a year to find statistics (1997 to 2010): ")
index_of =
int()
lines = []
for
item
in
emission_dict.values():
if
input_year
in item:
index_of = (item.index(input_year))
total = 0
i = 0
emissions_in_year = []
for
value
in
emission_dict.values():
if i != 0:
total +=
float(value[index_of])
emissions_in_year.append( list(emission_dict.values())[i][index_of])
i += 1
max_country_index =
int(emissions_in_year.index(str(max(float(str_value)
for
str_value
in
emissions_in_year))))
min_country_index =
int(emissions_in_year.index(str(min(float(str_value)
for
str_value
in
emissions_in_year))))
average_emissions = total / 195
max_emission =
list(emission_dict.keys())[max_country_index
+ 1]
min_emission =
list(emission_dict.keys())[min_country_index
+ 1]
print( f'In
{input_year}, countries with minimum and maximum
CO2 emission levels were: [{min_emission}] '
f'and [{max_emission}] respectively.')
print( f'Average
CO2 emissions in {input_year} were {"%.6f" %
round(average_emissions, 6)}')
print()
"""
Step 1: Take the input from user to visualize
data
"""
visualize_country = input( "Select
the country to visualize: ")
"""
Step 2: Getting the index of Country and
passing it to plot function, Setting the Title
and Label of Plot
"""
# From user entered value we extracted the
Index value of country
number =
list(emission_dict.keys()).index(visualize_country)
# Passed that index value to matplotlib plot
function. As x value we passed years and as y
value we passed emission value
plt .plot(list(map(float,
list(emission_dict.values())[0])),
list(map(float,
list(emission_dict.values())[number])))
# Given the Title and Lable to Plot
plt .title("Year
vs Emissions in Capita")
plt .xlabel("Year")
plt .ylabel("Emissions
in " +
visualize_country.title())
plt .show()
print()
|
|
| | | |
- Output:
Step1 - select a year ... |
|
Step2 - input year = 2000 |
|
Step3 - select the country ... |
|
Step4 - input country = Qatar |
|
Step 5 - to plot the Emissions in Qatar | |
| | |
|
2.12.3- Python Program to
display function of Matplotlib. Matplotlib
is a plotting library for the Python - 3 |
|
- In this
program, you'll learn to display function of
Matplotlib.
Matplotlib is a plotting library for the Python
programming language and its numerical
mathematics extension NumPy. It provides an
object-oriented API for embedding plots into
applications using general-purpose GUI
toolkits
project
file: Py-test.pyproj Using Microsoft
Visual studio 2019 Compiler - (IDE), to compile
Python
project / file
- Source Code:
Download this
Source Code at txt file - (0.45 MB
txt file) download
|
 |
Continue
|
Python Code,
to display function of Matplotlib - 3 | |
|
|
|
# Matplotlib is a
plotting library for the Python programming
language for creating static,
# animated, and interactive visualizations in
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(19680801)
data = np.random.randn(2, 100)
fig, axs = plt.subplots(2, 2, figsize=(5,
5))
axs[0, 0].hist(data[0])
axs[1, 0].scatter(data[0], data[1])
axs[0, 1].plot(data[0], data[1])
axs[1, 1].hist2d(data[0], data[1])
plt.show() |
|
| | | |
- Output:
|
| | |
| | |
| | |
|
Python Pages -
1
2
3
4
5
6 |
|
www.puresoftwarecode.com
: |
|
HUMANITIES
Institute |
ART Institute &
Others |
SOFTWARE
Institute - "Free, 120 Training Courses" |
CHRISTIANITY
Institute |
|
|
Python, Teach yourSelf Programs in
6 pages, in English |
|
Le HANDICAP c'est quoi ? (in
French) |
Basilica Architecture, in the Shape
of a Cross |
VISUAL STUDIO 2019, C# Programs, in English |
Holy BIBLE in 22 Languages and Studies
... |
Drugs and Treatment in English, french,
Arabic |
Old Traditional Lebanese
houses |
VISUAL STUDIO 2010 in
English |
220 Holy Christian
ICONS |
Classification of Wastes from the Source
in Arabic |
5 DRAWING Courses & 3
Galleries |
VISUAL STUDIO .NET, Windows & ASP in
English |
Catholic Syrian MARONITE Church
|
|
Meteora,
Christianity Monasteries - En, Ar,
Fr |
VISUAL STUDIO 6.0 in
English |
HOLY MASS of Maronite Church - Audio
in Arabic |
Christianity in the Arabian Peninsula in
Arabic |
Monasteries of Mount Athos &
Pilgrimage |
Microsoft ACCESS in
English |
VIRGIN MARY, Mother of JESUS CHRIST
GOD |
Summary of the Lebanese history in
Arabic |
Carved Rock Churches, in Lalibela,
Ethiopia |
PHP & MySQL in
English |
SAINTS of the Church |
LEBANON EVENTS 1840 & 1860, in
Arabic |
|
SOFTWARE GAMES in
English |
Saint SHARBEL - Sharbelogy in 10
languages, Books |
Great FAMINE in LEBANON 1916, in
Arabic |
my PRODUCTS, and Statistiques
... |
WEB DESIGN in English |
Catholic RADIO in Arabic, Sawt el
Rab |
Great FAMINE and Germny Role 1916,
in Arabic |
|
JAVA SCRIPT in
English |
Читать -
БИБЛИЯ и Шарбэль cвятой, in Russe |
Armenian Genocide 1915 in
Arabic |
4 Different
STUDIES |
FLASH - ANIMATION in
English |
|
Sayfo or Assyrian Genocide 1915 in
Arabic |
SOLAR Energy & Gas
Studies |
PLAY, 5 GAMES |
|
|
|
|
|
Christianity in Turkey in
Arabic |
WELCOME to LEBANON |
SAADEH BEJJANE
Architecture |
Andree Zouein
Foundation |
|
YAHCHOUCH, my Lebanese
Village |
CARLOS SLIM HELU Site. new
design |
REPORT, Cyber Attack Attacks the Current
Site |
Prononce English and French and Arabic
Letters |
ZOUEIN, my Family - History &
Trees | |
|
| | |