10th Class - Python
10th Class - Python
python
Python is a computer programming language often
used to build websites and software, automate tasks,
and conduct data analysis. Python is a general-
purpose language, meaning it can be used to create
a variety of different programs and isn't specialized
for any specific problems
or
Python is a high-level, interpreted, general-purpose
programming language. Its design philosophy
emphasizes code readability with the use of
significant indentation. Python is dynamically-typed
and garbage
What is
Programming
Language
As we know, to communicate with a person, we need a
specific language, similarly to communicate with
computers, programmers also need a language is
called Programming language. Before learning the
programming language, let's understand what is
language
What is Language
Programming
System Software Application software Language
Software
Programming
language software
X=1 Number(int)
y=1.2 Float
Z=1j Complex
P=‘ahmad’ String
Print(type(x))
Print(type(y))
Print(type(z))
What is Variable
keyboard=‘4000’
Computer=‘3000’
Print(int(keyboard)+int(Computer))
String
Properties
• We must write string on quotation we can write the
string in single quotation and also in double quotation
• X=“welcome to python”
• X=‘welcome to pyton’
• Print (x)
• Print(x.title())
• Print(x.upper())
• Print(x.lower())
String Properties
• First_Name=‘Ahmad Kareem’
• Last_Name=‘Popalzai’
• Full _Name=First_Name+’ ‘ +Last_Name
• Print(Full_Name)
print('ahmad kareem')
print('\tahmad naim')
print('languages:\npython\nc++\njavascript\n')
print('languages:\n\tpython\n\tc++\n\tjava script\n’)
name=‘ahmad ‘
Print(name.rstrip())
Print(name.Lstrip())
Print(name.strip())
Number Properties
• In python we us int and float for numbers
• We can add operation on all numbers
• Int
• X=“289”
• Float • Print(Type(x))
• 10/30
• X=int(x)
• Print(type(x))
• Print(x)
• X=-7.5
• Print(abs(x))
Number Properties
Operator priority
• ()
• **
• */ the operator which is on the left
• +
• -
Runtime error
Syntax Error
Syntax error is a grammerical error in python
print 123
print(123)
Runtime Error
A runtime error in a program is an error that occurs while
the program is running after being successfully compiled
open(‘flower.jpg’)
Input from keyboard or user
name=input(“Enter your name:”)
X=int(input(Enter first Number:”))
Print(“your name is:”)
y=int(input(Enter second Number:”))
Print(name)
Total=x+y
---------------------------------------------
Print(total)
name=input(“Enter your name:”)
Print(f“your name is {name}”)
lable1.grid(row=0,column=0,padx=5,pady=10)
textbox1=Entry(window,fg='blue',font=('Arial',14))
textbox1.grid(row=0,column=1)
window.mainloop()
import tkinter as tk
from tkinter.ttk import *
root = tk.Tk()
Creating
root.geometry('100x100')
Buttons
btn = Button(root, text='Click me!', command=root.destroy)
btn.pack(side='top')
root.mainloop()
from tkinter import * Creating
Scroll Bar
master = Tk()
w = Scale(master, from_=0, to=42)
in Python
w.pack()
w = Scale(master, from_=0, to=200, orient=HORIZONTAL)
w.pack()
mainloop()
The Python turtle library is a built-in module
that provides a fun and interactive way to learn What is
Turtle
programming concepts. It’s based on the Logo
programming language and allows users to
create pictures and shapes on a screen using a
metaphorical “turtle” Here are some key points
about the Python turtle library:
Library
1.Virtual Canvas: The turtle library gives you
a virtual canvas where you can draw and
create various types of shapes and images.
2.The Turtle: The onscreen pen that you use for
drawing is called the turtle. You can move this
turtle around the canvas, and it leaves a trail as
it moves.
A conditional statement in Python is a
Condition
programming construct
that allows you to make decisions
and execute different blocks
of code based on certain conditions.
in python
It allows you to control the flow
of your program based on whether a
condition is true or false
Conditional Statements are followings
1- IF Condition
2- IF and elf
3- IF AND
in python
4- IF OR
5- IF Not
Comparison Operator
Comparison operator can Compares numbers and
perform evaluations. And the result of comparision
operator can be true or false.
> X=2
< Z=3
>=
Print(x>y)
<=
Print(x<=y)
!=
Print(x==y)
==
Condition in python
X=float(input(“please Enter a number”))
if x>0:
print(“the Num is positive”)
else:
number=float(input(“please Enter a number”))
print(“the num is Negative”)
if number%2==0:
print(“the Num is even”)
else:
print(“the num is odd”)
today = 'Saturday' if today=='Sunday' or today=='Saturday': print('Today is off. Rest at home.')
If x != y:
print(‘x is not equal to y’)
Else
print(“x and y variable values are equal”)
Name=str(input(Please Enter Name”))
Job=str(input(please Enter Job”))
salary=int(input(please Enter salary))
If job != ‘doctor’:
print(salary+5000)
Else:
Print(salary)
Print(“you are doctor”)
Python supports the usual logical conditions from
mathematics:
Equals: a == b Condition
Not Equals: a != b
Less than: a < b
in python
Less than or equal to: a <= b
Greater than: a > b
Greater than or equal to: a >= b
These conditions can be used in several ways, most
commonly in "if statements" and loops.
An "if statement" is written by using the if keyword.
In Python, loops are
essential for executing a Loops in
block of code repeatedly python
until a specific condition is
met. Let’s explore the two
main types of loops in
Python:
Python has two primitive loop commands:
1. while loops
2. for loops Loops in
Python
1- while loop
A while loop executes a block of statements
repeatedly as long as a given condition remains true
i=1
Loops in
while i < 6:
print(i)
i += 1 Python
count = 0
while count < 3:
print("Hello ")
count += 1
The break Statement
With the break statement we can stop the loop even if
the while condition is true: Loops in
i=1
while i < 6:
Python
print(i)
if i == 3:
break
i += 1
-----------------------------
i=1
while i <= 100: Loops in
print(i)
if i == 7:
Python
break
i += 1
Arrays are a fundamental data structure, and an
important part of most programming languages. In
Python, they are containers which are able to store
Array in
more than one item at the same time. Specifically, Python
they are an ordered collection of elements with every
value being of the same data type
There are two types of array in python
1- One Dimensional Array
2- Two Dimensional Array
Types of
Array
1- One Dimensional Array
This types of array has one row and multiple column
f
int
float
array in
python
From array import *
Array name = array (‘type code’,[ elements])
Array
Example Syntax
From array import *
Stu_roll_num=array(‘ i ‘ ,[2345,2346,2347,2348,2349])
Print(stu_roll_num[0])
For Loops
With the for loop we can execute a set of
statements, once for each item in a list,
tuple, set etc.
for x in "banana":
print(x)
For Loops
------------------------------------------------------------ and Array
Examples
s = "Geeks"
for i in s:
print(i)
for number in range(5):
print("Thank you")
For Loops
------------------------------------------------------------ and Array
Examples
for i in range(1,n):
print(i)
for i in range(0, 10, 2):
print(i)
For Loops
------------------------------------------------------------ and Array
Examples
given_range = 10
for i in range(given_range):
if i%2==0:
print(i)
fruits = ["apple", "banana", "cherry"]
for x in fruits:
For Loops
print(x) and Array
------------------------------------------------------------ Examples
list = [1,2,4,6,88,125]
for i in list:
print(i)