You are on page 1of 6

1-print("hello world") appuye run pour avoir le resultat

2- print(" /|")
print(" / |")
print(" / |")
print("/___|")
resultat un triangle
3-variables:
print("there was a boy called adel")
print("he was 85 years old")
print("he liked his name adel")
print("but wasn't happy about being 85")
lorsque tu as beaucoup de ligne c fatiguant de changer le nom,age,.. donc ndiro
character_name = "sidahmed" ex:
character_name = sid
print("there was a boy called " +character_name+ " sid")
print("he was 19 years old")
print("he liked his name " +character_name)
pour que les phrases ne seront pas coller on fait un espace hna:
"espace+ch.. ET MEME DANS CE CAS : ..name+ESPACE"espace...
-boolean hwese 3liha !
4- strings :
-print("code\nzilla") ki dir \n t3tik partie lwele f stere ou deuxieme partie fi
stere
-print("code\"zilla") resultat -> code"zilla
-print("code\tzilla") \t dirlk espace 4 FOIS entre les deux parties
-text = "SIdAhmed"
print(text.lower()) ymdlk text t3k minuscule
print(text.upper()) ymdlk text majuscule
print(text.islower())) y9olk wela text t3k raho minuscule wela non ou yjwebe b true
or false
print(text.isupper()) kifkif brk ychof wela raho majuscule
print(text.lower().islower()) hedi yrdlk text t3k minuscule oumb3D YCHOFLK WELA
RAHO MINUSCULE LA MEME CHOSE POUR (upper)
print(len(text)) hedi ychoflk text t3k ch7L fih mn lettre ex : CODEZILLA FIHA 9
print(text[0]) y3tilk ama lettre raho lwele ,f linformatique calcul ybda b 0 1
2 ....
print(text.index("lettre")) y3tik rang t33 HED LETTRE WELA LETTRE HEDI MTEXISTICHE
YKHROJLK ERREUR
print(text.replace("7eja","b 7eja"))
5- numbers :
print(10%3) resultat 1 psq % y3tik le reste
my_num = 5
print(str(my_num)+" my favorite number")
resultat: 5 my favorite number
my_num = -5
print(abs(my_num)) ymdna la valeur absolue t3 num
print(pow(3,2)) ymdlk 3^2 ou li hiya 9
print(min(3,5)) tmdlk la valeur minimale kima hna 3
print(max(3,5)) tmdlk 5
print(round(3.2)) tmdlk 3
print(round(3.7)) tmdlk 4

from math import * from math import *


print(floor(3.2)) TMDLK 3 print(floor(3.7)) tmdlk 3
print(ceil(3.2)) tmdlk 4 print(ceil(3.7)) tmdlk 4

from math import *


print(sqrt(nombre)) tmdlk la racine
6- contributions (modkhalte):
name = input("enter your name: ")
print("hello " +name)
ki dir run y9olk enter your name nta aktb asmek
oumb3d y3tik resultat kima hna hello sideh

name = input("enter your name: ")


age = input("enter your age: ")
print("hello " +name+ " and your age is " +age)
resultat hello sideh and your age is 19

7- build calculator:
num1 = input("enter the first no: ")
num2 = input("enter the second no: ")
result = num1+num2
print(result) oumb3d dkhl les numbers z3ma lwele 10 ou deuxieme 5 YMDLK 105
WELA 7EBINA YMDNA LA SOMME NDIRO result = int(num1)+int(num2)

zid b int( mn9droche ndkhlo numero b virgule donc hna nkhdmo b float(num1)+....

8- build madlibs (cree jeu): trees=arbres , mean=moyenne

color = input("enter a color: ")


plural_noun = input("enter a plural noun: ")
adjective = input("enter an adjective: ")
print("trees are "+color)
print(plural_noun+" are mean")
print("please keep it "+adjective)
RESULTAT :
trees are red
cars are mean
please keep it clean

9- listes
freinds = ["example", "sideh", "python", "leroy"]
print(freinds[2])
ymdlk python , wela drna z3ma print(freinds[-1]) ymdlk leroy chghol ybda mla fin
wela drna print(freinds[0:3]) ymdna klma lwela ou deuxieme ou troisieme mais
qaurtieme mydkhlhche

ki ndiro : print(freinds[0:]) ybda b klma lwela hta lekhra


10-
codezilla = ["programming", "python", "tutorial", "html", "css"]
tutorial = ["extend", "list1", "codezilla"]
codezilla = codezilla + tutorial
print(codezilla)
resultat: ymdna kolch wsh kyn fi codezilla et tutorial , n9dro au lieu ndiro +
NDIRO PRINT(codezilla, tutorial) wela codezilla.extend(tutorial)
print(codezilla)
wela: codezilla += tutorial print(codezilla)

.append yzid heja li t7b


.insert tzidlk wsh t7b ou win t7b
.remove tn7ilk wsh t7b
.clear() tn7ilk kolch
.pop() tn7ilk lelement lokhere
wela t7b tkhrj lelement lekhre dir what_was_popped = codezilla.pop()
print(what_was_popped)
print(codezilla.index("html")) ymdlk trtib t3 html

codezilla.count("programming")) t90lk ch7l mn khtra mktoba progrzmming

codezilla.sort()
print(codezilla)
yktblk wsh 3ndk 3LA 7SEB L'ALPHABET
wela 3ndk des numeros ytrblk msghir lkbire

list_news = codezilla
codezilla.append(1)
print(list_new)
print(codezilla)
resultat
['python', ....., '1'] ...1
['python.............]
BSA7 WELA DERNA
list_new = codezilla.copy() mtkhrojnche 1 FLWELA

11- tuples :
coordinates = (23, 45)
print(coordinates[1]) tkhrojlk 45 BRK

coordinates = (23, 45)


list_of_tuples = [(2, 3), (6, 5)]
print(list_of_tuples)

12-functions :
def say_hi():
print("hello user")
print("first")
say_hi()
print("second")
resultat: first
hello user
second

def say_hi(name, age):


print("hello " +name+ " your age is " +age) n9dro nktbo print("hello "
+name+ " yourage is " +str(age))
say_hi("mahmoud", 35)

say_hi("mahmoud", "35")

def cube(num):
return(num*num*num)
print(cube(3)) resultat : 27

def sum(num1, num2)


return num1+num2
print(sum(2, 4))
resultat 6

13- conditionals :
is_hungry = True
if is_hungry == true: n9dro ndiro if is_hungry:
print("go eat")
else:
print("do not eat")

is_hungry = True
wants_to_eat = True
if is_hungry or wants_to_eat:
print("go eat")
else:
print("do not eat")

resultat tout depend le "True ou False"

is_hungry = true
wants_to_eat = True
if is_hungry and wants_to_eat:
print("go eat")
else:
print("do not eat")

is_hungry = True
wants_to_eat = False
if is_hungry and wants_to_eat:
print("go eat")
elif is_hungry and not wants_to_eat:
print("eat so u can survive")
elif not is_hungry and wants_to_eat:
print("do not eat u are not hungry")
else:
print("do not eat")

resultat : eat so u survive

14- comparisons :

def max_num(num1, num2, num3):


if num1 >= num2 and num1 >= num3:
return num1
elif num2>= num1 and num2>= num3:
return num2
else:
return num3
leroy = max_num(2, 5, 10)
print(leroy)

def match_string(str1, str2):


if str1 == str2:
print("the strings do match")
else:
print("the strings do not match")

match_string("codezilla", "islam")
resultat : th strings do not match

15-calculator 2 :
num1 = float(input("please enter the first number"))
operator = input("please enter the operator")
num2 = float(input("please enter the second number"))
if operator == "+":
print(num1 + num2)
elif operator == "-":
print(num1 - num2)
elif operator == "/":
print(num1 / num2)
else:
print("wrong operator please try again")

16- dictionaires :
convert_math = {}
"jan": "january",
"feb": "febraury",
"mar":"march"
print(convert_math["mar"]) ou print(convert_month.get("mar"))
resultat : march

17- while loop : repitition


i = 1
while i <= 10:
print(i)
i = i+1 ou i+= 1
print("the loop has ended")
resultat: 1 2 ... 10
lokan ndiro while true: fi placete while i<= 10: ymdna hta linfini

i=1
while i <= 10
print(i)
i += 1
else:
print("the condition is not true")
print("the loop has ended")

i = 1
while i <=10 :
i += 1
if i == 6:
continue
print(i)
resultat : ykhrjo men 2 HTA 11 APART 6
9LBNA PRINT(i) c pour ca khrjt lkhra

i = 1
while i <= 10:
i+= 1
print(i)
if i == 6:
break
print(i)
print("the loop has ended")
resultat: mn 2 HTA 5 PSQ HBSNA PROGRAMME

You might also like