Skip to content

Commit afa4dc5

Browse files
authored
Add files via upload
0 parents  commit afa4dc5

38 files changed

+620
-0
lines changed

1-variables.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
#string
3+
'''
4+
name = "amine"
5+
print("hello"+name) #printing + concatinating
6+
print(type(name)) #type of the variable = <class str>
7+
8+
first_name = "Amine"
9+
last_name ="shx"
10+
full_name = first_name +" "+ last_name #concatinating strings + space between
11+
print (full_name)
12+
13+
'''
14+
# int data type
15+
16+
'''
17+
age= 21
18+
age= age +1 # incriment the age by one
19+
print(age)
20+
print(type(age)) #<class int>
21+
#print("your age is:"+age) # error cuz can only concatenate str (not "int") to str
22+
print("your age is "+str(age)) # printing age along a string => the result is sting + string
23+
print(type(str(age))) # str() turn a variable to a string
24+
25+
'''
26+
27+
# float data type
28+
29+
'''
30+
31+
height= 180.5
32+
print(height)
33+
print(type(height)) # <class float>
34+
print ("your height is :"+str(height)+" cm")
35+
36+
'''
37+
38+
#boolean
39+
40+
'''
41+
42+
smthn = False
43+
print(smthn)
44+
print(type(smthn)) #<class 'bool'>
45+
print("there is smthn ?" +" "+str(smthn))
46+
47+
'''
48+
49+
#multiple assignment
50+
51+
'''
52+
53+
#normal assignment
54+
name = "amine"
55+
age= 22
56+
attractive= True
57+
print(name)
58+
print(age)
59+
print(attractive)
60+
61+
#multiple assignment
62+
63+
name,age,attractive = "shx", 22, True
64+
print(name)
65+
print(age)
66+
print(attractive)
67+
68+
X=Y=Z=A=10
69+
print(X)
70+
print(Y)
71+
print(Z)
72+
print(A)
73+
74+
'''

10-for-loops.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
'''
3+
4+
for i in range(10):
5+
print(i)
6+
7+
for i in range(50,100):
8+
print(i+1)
9+
10+
for i in range(50,101,2):
11+
print(i)
12+
13+
for i in "amine shx":
14+
print(i)
15+
16+
'''
17+
18+
import time
19+
20+
for seconds in range(10,0,-1):
21+
print(seconds)
22+
time.sleep(1)
23+
print("happy new year")

11-nested-loops.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
rows= int(input("give me the number of rows"))
4+
columns= int(input("give me the number of columns"))
5+
6+
for i in range(rows):
7+
for j in range(columns):
8+
print("@", end="") #printing in same ligne
9+
print()

12-break-continue-pass.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#break= used to terminate the loop entirely
2+
#continue = skips to the next iteration of the loop
3+
#pass = does nothing, acts as a placeholder
4+
5+
'''
6+
7+
while True:
8+
name=input("what is your name ")
9+
if name !="":
10+
break
11+
12+
'''
13+
14+
'''
15+
16+
phone_number= "123-456-7890"
17+
18+
for i in phone_number:
19+
if i == "-":
20+
continue
21+
print(i, end="")
22+
23+
'''
24+
25+
for i in range(1,21):
26+
if i == 13:
27+
pass
28+
else:
29+
print(i)

13-lists.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
food = ["pizza","hamberger","hotdog","spaghetti"]
4+
5+
food[0]="sushi"
6+
food.append("ice cream") #adding an elemnt to a list
7+
food.remove("hotdog") #removing an element
8+
food.pop() #removing the last element
9+
food.insert(0,"cake") #inserting an element to the list with an index
10+
food.sort() #will sort the list alphabitcaly
11+
food.clear() #removing all the element
12+
13+
for x in food :
14+
print(x)

14-2D-lists.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
drinks=["coffe", "soda", "tea"]
3+
dinner=["pizza", "hamburger", "hotdog"]
4+
dessert= ["cake","ice cream"]
5+
6+
food=[drinks,dinner,dessert]
7+
print(food)
8+
print(food[0][0])

15-tuples.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#tuple = collection which is order and unchangeable used to group together related data
2+
3+
student= ("amine",22,"male")
4+
5+
print(student.count("amine")) #count is how many time does that element apire in the tuple
6+
print(student.index("male")) #printing the index
7+
8+
for x in student:
9+
print(x)
10+
11+
if "aine" in student:
12+
print("yes")
13+
else:
14+
print("no")

16-sets.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# set = collection which is unordered , unindexed , no duplicate values
2+
3+
utensils = {"fork", "spoon" , "knife"}
4+
dishes={"bowl","plate", "cup","knife"}
5+
6+
dinner_table=utensils.union(dishes)
7+
8+
print(utensils.difference(dishes)) # this prints what utensils have and dishes doesn't
9+
print(utensils.intersection(dishes)) # this prints what this two sets have in communt
10+
utensils.update(dishes)
11+
utensils.add("napkin")
12+
utensils.remove("fork")
13+
utensils.clear()
14+
for x in utensils:
15+
print(x)

17-dictionaries.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# dictionary = A changeable, unordered collection of unique key:value pairs
2+
# fast because they use hashing, allow us to access a value quickly
3+
4+
capitals = {'USA':'Washington DC',
5+
'India':'New Dehli',
6+
'china':'Beijing',
7+
'Russia':'moscow'}
8+
9+
print(capitals['USA']) # printing the value is th dictionary[key]
10+
print(capitals.get('Germany')) # get('germany')= None
11+
print(capitals.keys()) #printing keys
12+
print(capitals.items()) #printing all the dictionary
13+
14+
for key,value in capitals.items():
15+
print(key,value)
16+
17+
18+
capitals.update({'Germany':'berlin'}) #adding a new key and value
19+
capitals.update({'USA':'Las Vegas'}) #changing the value
20+
capitals.pop('china') # clearing a pair with china key
21+
capitals.clear() #clearing every thing

18-indexing.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
3+
name = "amine shx"
4+
'''
5+
if name[0].islower():
6+
name= name.capitalize()
7+
8+
print(name)
9+
10+
'''
11+
12+
13+
#spliting
14+
first_name, last_name = name.split(" ")
15+
print("First name: ", first_name)
16+
print("Last name: ", last_name)

19-functions.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
def hello(name):
4+
print("hello "+name)
5+
6+
my_name="amine shx"
7+
8+
hello(my_name)

2-string-methods.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name= "amine shx"
2+
3+
print(len(name)) #length of a string
4+
print(name.find("a")) #printing index of the cracter and index of a = 0 , m=1 , s=6
5+
print(name.capitalize()) # this will only capitalize the first letter result of this is = Amine shx not AMINE SHX
6+
print(name.upper()) # uppercassing the string and result = AMINE SHX
7+
print(name.lower()) # i think u got this one
8+
print(name.isdigit()) # a boolean result checking if the variable is a digit or not
9+
number = "123"
10+
print(number.isdigit()) # results = True cuz 123 is a digit
11+
print(name.isalpha()) #a boolean result checking if the variable is an alphabatic caracters results = False .......eh ? false why ? cuz there is space in amine shx ...
12+
name1= "amine"
13+
print(name1.isalpha()) # results = True
14+
print(number.isalpha()) # resuts = False
15+
print(name.count("a")) # count how many given caracters in a string so here results = 1
16+
print(name.replace("a","k")) # replacing a in string with k so results = kmine sh
17+
print(name*3) # displaying a variable 3 times its like loop lol

20-return.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
def mult(num1, num2):
4+
results= num1*num2
5+
return results
6+
7+
print(mult(7,5))

21-keyword.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#keyword argument = arguments preceded by an identifier when we pass them to a function
2+
# the order of the arguments doesn't matter, unlike positional arguments
3+
# python knows the names of the arguments that our function receives
4+
5+
#when order matters
6+
7+
'''
8+
9+
def hello(first,middle,last):
10+
print("hello "+first+" "+middle+" "+last)
11+
12+
hello("amine","shx","cv")
13+
14+
'''
15+
16+
#when order doesn't matter
17+
18+
'''
19+
20+
def hello(first,middle,last):
21+
print("hello "+first+" "+middle+" "+last)
22+
23+
hello(middle="shx",last="cv",first="amine")
24+
25+
'''

22-nested-func-calls.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# nested function calls = function calls inside other function calls
2+
# innermost function calls are resolved first
3+
# returned value is used as argument for the next outer function
4+
5+
# num = input("enter a whole positive number: ")
6+
# num = float(num)
7+
# num = abs(num)
8+
# num = round(num)
9+
# print(num)
10+
11+
12+
print(round(abs(float(input("enter a whole positive number: ")))))

23-variable-scope.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# scope = the region that a variable is recognized
2+
# A variable is only available from inside the region it is created
3+
# A global and locally scoped versions of a variable can be created
4+
5+
# L = local E = enclosing G = Global B= Built-in
6+
7+
name = "bambam" #global scope (available only inside & outside function)
8+
9+
def display_name():
10+
#name = "bimbim" # local scope (available only inside this function)
11+
print(name)
12+
13+
14+
display_name()
15+
print(name)

24-args.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# *args = parameter that will pack all arguments into a tuple
2+
# useful so that a function can accept a varying amount of arguments
3+
4+
5+
# def add(num1,num2):
6+
# num = num1+ num2
7+
# return num
8+
9+
# print(add(1,2,3)) # we cant add three argument
10+
11+
def add1(*args):
12+
sum = 0
13+
args = list(args)
14+
args[0]=0
15+
for i in args:
16+
sum += i
17+
return sum
18+
19+
print(add1(1,2,3,4,5))

25-kwargs.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ** kwargs = parameter that will pack all arguments into a dictionary
2+
# useful so that a function can accept a varying amount of keyword argumnets
3+
4+
# def hello(first, last):
5+
# print("hello "+ first +" "+last)
6+
7+
# hello(first="amine",last="shx") # cant add a 3rd argument
8+
9+
def hello1(**kwargs):
10+
#print("hello "+kwargs['first']+" "+kwargs['last'])
11+
print("hello",end=" ")
12+
for key,value in kwargs.items():
13+
print(value,"",end="")
14+
hello1(first="amine",middle="bimbim",last="shx")

0 commit comments

Comments
 (0)