Rappel_python (2) (1)
Rappel_python (2) (1)
Ex1#print in python
print("Hello Python")
print(len(text_1))
print(len(text_2))
print(3*5+6)
print(3*(5+6))
print(10 % 3)
my_num = -5
print(abs(my_num))
print(str(my_num)+" my favorite number")
print(pow(10,4))
Hammadi Oumaima
Introduction Python LSE3
print(max(4,10))
print(min(4,10))
print(round(3.7))
print(round(3.2))
print(bool("ok"))
print(bool(15))
print(bool(""))
print(bool(0))
#print(lessons[:2])
print(lessons[2:])
print(lessons[1:])
print(lessons[0])
Hammadi Oumaima
Introduction Python LSE3
####
def say_hello(name,age):
print("hello "+name+" your age is "+str(age))
say_hello("Ahmed",15)
def cube(number):
number*number*number
cube(3)
def cube(number):
return number*number*number
print(cube(3))
Autrement :
def cube(number):
return number*number*number
result=cube(3)
print(result)
Hammadi Oumaima
Introduction Python LSE3
def match_string(str1,str2):
if str1 != str2 :
print("the string don't match")
else :
print("the string do match")
(match_string("Master_Bio1","Master_Bio1"))
i=1
while i<= 5 :
print(i)
i+=1
print("the loop has ended")
i=1
Hammadi Oumaima
Introduction Python LSE3
while i<= 5 :
i+=1
print(i)
i=1
while i<= 10 :
i+=1
if i == 5:
break
print(i)
i=1
while i<= 10 :
i+=1
if i == 5:
continue
print(i)
Students=["amal","mohamed","mariem","zeinbe","omar"]
Hammadi Oumaima
Introduction Python LSE3
for x in range(3,9):
print(x)
for x in range(10):
if x % 2 ==0:
print(x,"est un nombre pair")
else :
print(x,"est un nombre impair")
Text="MasterBio1"
print(len(Text))
print(range(len(Text)))
for x in range(len(Text)):
print("La lettre d'index ",x,"est",Text[x])
return result
power(2,3)
#print(power(2,3))
Hammadi Oumaima
Introduction Python LSE3
]
print(no_list)
for row in no_list :
print(row)
print('Python')
Hammadi Oumaima
Introduction Python LSE3
Student_1=Student("Ala",10,"Infomatique")
Student_2=Student("Salma",20,"Physique")
print(Student_1.age,Student_1.name)
print(Student_2.age,Student_2.departement)
class Student:
def __init__(self, name, age, departement):
self.name = name
self.age = age
self.departement = departement
def is_young(self):
if self.age >= 20:
return True
else:
return False
#app.py
Student_1=Student("Ala",10,"Infomatique")
Student_2=Student("Salma",20,"Physique")
print(Student_1.age,Student_1.name)
print(Student_2.age,Student_2.departement)
print(Student_2.age,Student_2.is_young())
print(Student_1.age,Student_1.is_young())
Hammadi Oumaima
Introduction Python LSE3
class FamilyTeacher(Teacher):
def what_specialization(self):
print("i work with families")
def paid_by_who(self):
print("i get paid by the people")
#app.py
teacher_1=Teacher() #Constructor
teacher_2=FamilyTeacher() #Constructor
teacher_1.studied_years()
teacher_1.works_where()
teacher_1.paid_by_who()
teacher_2.what_specialization()
teacher_2.paid_by_who()
teacher_2.studied_years()
teacher_2.works_where()
teacher_2.paid_by_who()
Hammadi Oumaima
Introduction Python LSE3
Hammadi Oumaima