· 8 years ago · Jun 05, 2018, 12:38 AM
1(1)---------------if, else, and----------------conditions الشروط ÙˆØ§Ù„ØØ§Ù„ات
2num1 = 15
3num2 = 15
4if num1 == num2 :
5 print ("yes")
6>>> yes
7
8num1 = 15
9num2 = 15
10if num1 == num2 :
11 print ("yes")
12else :
13 print ("no")
14>>> no
15
16num1 = 10
17num2 = 11
18if num1==10 and num2==11 :
19 print ("Yes, they are..!")
20>>> Yes, they are..!
21(2)---------------elif, or, not---------------conditions الشروط ÙˆØ§Ù„ØØ§Ù„ات
22num1 = 10
23num2 = 15
24if num1==num2 :
25 print ("yes, num1 = num2")
26elif num1==10 and num2==15 :
27 print ("yes, num1=10 and num2=15")
28else :
29 print ("no one is correct")
30>>> yes, num1=10 and num2=15
31
32num1 = 10
33num2 = 15
34if num1==10 or num2==21205454584 :
35 print ("yes")
36>>> yes
37
38num1 = 10
39num2 = 15
40if not num1==10 :
41 print ("no")
42>>>
43(3)---------------------------------------------Loops ØÙ„قات التكرار
44num1 = 1
45while num1 <10:
46 print ("Good Morning")
47>>> Good Morning
48(4)--------------------while--------------------Loops ØÙ„قات التكرار
49a = 0
50while a==0:
51 print (a)
52>>> هيعد يطبع ÙØ§ØµÙار لا نهاية لها مش هيوقÙ
53Ctrl+C عشان توقÙوا هتضغط
54
55a = 0
56while a<100:
57 a=a+1
58 print (a)
59>>> هيعد يطبع الارقام من 0 لغاية 100 ويوقÙ
60
61start = "mohamed"
62end = "@gmail.com"
63a = 0
64while a<10000 :
65 a = a + 1
66 print (start+str(a)+end)
67>>> لغاية ميوصل لعشرتلا٠ايميل @gmail.com Ù‡ÙŠÙØ¶Ù„ يطبع كلمة Ù…ØÙ…د ويزود جنبها ارقام وبعدها
68(5)--------------for-------------------------Loops ØÙ„قات التكرار
69range (1,10)
70>>> range (1, 10)
71
72list (range(1,10))
73>>> [1, 2, 3, 4, 5, 6, 7, 8, 9]
74
75s = "hello"
76for a in s:
77 print (a)
78>>> h
79 e
80 l
81 l
82 o
83
84a = ["Ahmed", 1, 0144, "Khaled"]
85for b in a:
86 print (b)
87>>> Ahmed
88 1
89 0144
90 Khaled
91(6)------------------------------------------- Loops ØÙ„قات التكرار
92email = "ahmed@gmail.com"
93password = 123456
94password_list=[1234,"asdsa","asjd","asdsad","asdsadasd",123456,"asjdksja"]
95for password in password_list :
96 print (password)
97 if password == 123456 :
98 print (password,"password found")
99>>> 1234
100 asdsa
101 asjd
102 asdsad
103 asdsadasd
104 123456
105 (123456, 'password found')
106 asjdksja
107(7)--------------nested loobs------------Loops ØÙ„قات التكرار
108for i in list(range(1,100)):
109 for x in list(range(1,200)):
110 print (x)
111 print (i)
112>>> هيطبع من 1 ل 199 وبعدها هيطبع من 1ل99 وبعدها يرجع تاني يطبع من 1 ل 199 وبعدها هيرجع تاني يطبع من 1 ل99 الي ما لا نهاية
113(8)--------------break,continue,pass----------Loops ØÙ„قات التكرار
114s="python"
115for i in s:
116 print (i)
117>>> P
118 y
119 t
120 o
121 n
122
123s="python"
124for i in s:
125 if i=="h" :
126 break
127 print (i)
128>>> P
129 y
130 t
131
132a=0
133while a>100:
134 a=a+1
135 print(a)
136>>> هيعد يطبع من 1 ل100
137
138a=0
139while a<100:
140 a=a+1
141 if a==90:
142 break
143 print(a)
144>>> هيطبع من 1 ل89
145
146usernum=int(input("Enter your number : "))
147numbers=[1,2,3,4,5,6,7,8,9]
148for number in numbers:
149 if usernum==number :
150 print("The number is correct")
151 break
152else:
153 print("Try again")
154>>> Enter your number : 3
155>>> The number is correct
156
157while True:
158 usernum=int(input("Enter your number : "))
159 numbers=[1,2,3,4,5,6,7,8,9]
160 for number in numbers:
161 if usernum==number :
162 print("The number is correct")
163 break
164 else:
165 print("Try again")
166 >>> Enter your number : 3
167 >>> The number is correct
168 >>> Enter your number :
169وهكذا Ù‡ÙŠÙØ¶Ù„ شغال كدا Ùهمت
170(9)--------continue,pass-----------------------Loops ØÙ„قات التكرار
171s = "python"
172for a in s:
173 if a == "h":
174 continue
175 print (s)
176>>> p
177 y
178 t
179 o
180 n
181
182s = "python"
183for a in s:
184 if a == "h":
185 pass
186 print (s)
187>>> p
188 y
189 t
190 h
191 o
192 n
193(10)---------ازاي تعمل دالة جديدة Ù„Ù†ÙØ³Ùƒ---------------Functions الدوال
194def ahmed():
195 print("ahmed")
196
197ahmed()
198>>> ahmed
199(11)------------------كيÙية انشاء دالة جديده Ù„Ù†ÙØ³Ùƒ-------------Functions الدوال
200def ahmed():
201 print("ahmed")
202
203def ahmed(a):
204 print ("Ahmed"+a)
205
206ahmed (" Mohamed")
207>>> 'ahmed Mohamed'
208(12)----------ازاي تعمل دالة بتجمع بين رقمين او اكتر----------------Functions الدوال
209def add():
210 print (1+1)
211add()
212>>> 2
213
214def add(a,b):
215 print (a+b)
216add (1,25)
217>>> 26
218
219def add(a,b):
220 print (a-b)
221
222def add(a-b):
223 print (a-b)
224(13)-------------ازاي ØªØØ· دالة انت اللي عاملها Ùمتغير-----------Functions الدوال
225def sub(first_num,Second_num):
226 print (first_num-Second_num)
227a = sub(5-2)
228>>> 3
229print (a)
230>>> None
231*None مشكلة*
232*ØÙ„ها*
233def sub(first_num,Second_num):
234 return (first_num-Second_num)
235sub(5,2)
236>>> 3
237a = sub(5,2)
238print (a)
239>>> 3
240*Add وبكدا نقدر نستغني عن دالة*
241(14)---------------------ازااي تعملي الة ØØ§Ø³Ø¨Ø© باللي اتعلمناه-------------------------Functions الدوال
242ef loop():
243 a = 0
244 while a<100:
245 print (a)
246>>> loob()
247>>> هيعد يطبع Ø§ØµÙØ§Ø± الي ما لا نهاية
248
249
250def add(a,b):
251 return a+b
252
253>>> add (10,20)
25420
255
256
257
258(دا كود كامل ع بعضو لعمل الة ØØ§Ø³Ø¨Ø©)
259print ("*"*20)
260def add(x,y):
261 return x+y
262
263def sub (x,y):
264 return x-y
265
266def multi(x,y)
267 return x*y
268
269user_input = input ("Enter operation number : ")
270
271user_input2 = input ("Enter The first number : ")
272user_input3 = input ("Enter The second number : ")
273if user_input == "1" :
274 print (add(user_input2 + user_input3))
275
276user_input4 = input ("Enter the first number : ")
277user_input5 = input ("Enter the second number : ")
278if user_input == "2" :
279 print (sub(user_input4 - user_input5))
280
281user_input6 = input ("Enter the first number : ")
282user_input7 = input ("Enter the second number : ")
283if if user_input == "3" :
284 print (multi(user_input6 * user_input7))
285(15)--------------------------الاعداد ÙÙŠ الدوال--------------------------------------Functions الدوال
286def hello(name):
287 def hello1():
288 return ("Hello ")
289 print (hello1() + name)
290
291>>> hello ("World")
292Hello World
293>>> hello("Ahmed")
294Hello Ahmed
295(16)-----------------------------------------------------العمليات ÙÙŠ الدوال---------------Functions الدوال
296def ahmed():
297 print("Ahmed")
298>>> ahmed()
299Ahmed
300
301def say_name():
302 ahmed()
303>>> say_name()
304Ahmed
305
306def ahmed(name,age,gender):
307 print ("my name is : ",name)
308 print ("my age is : ",age)
309 print ("my gender is : ",gender)
310>>> ahmed("Ahmed Muhammed" , 20, "Male")
311my name is : Ahmed Mohamed
312my age is : 20
313my gender is : Male
314
315def mohamed():
316 ahmed("Ahmed Muhammed" , 20, "Male")
317
318>>> mohamed()
319my name is : Ahmed Mohamed
320my age is : 20
321my gender is : Male
322(17)---------------------اسناد دالة لمتغير(العمليات ع الدوال)-------------Functions الدوال
323def name(): *دي الدالة اللي عملناها*
324 return ("Ahmed")
325>>> def myprint(name): *دي بنكمل عالدالة ÙØ³Ø·Ø± تاني *
326 print (name)
327>>> myprint("Ahmed") *ودا الامر اللي كتبناه*
328Ahmed
329>>> myprint(name()) *ودا امر تاني *
330Ahmed
331>>> def xname(): *ودي دالة جديده عملناها*
332 print("Ahmed")
333>>> xname() *ودا الامر اللي اديناهولها*
334Ahmed *ودي النتيجة*
335>>> def xname(): *عملنا دالة جديده وعدلنا Ùيها*
336 return ("Ahmed")
337>>> xname() *اديننالو امر الدالة عشان يطبع اØÙ…د*
338'Ahmed'
339>>> x = xname() *ØØ·ÙŠÙ†Ø§ الدالة Ùمتغير*
340>>> print(x) *طبعنا المتغير*
341Ahmed *ودي النتيجة*
342(17)----------------------------------Functions الدوال
343def myprint(*args):
344 print (args)
345>>> myprint("Ahmed")
346('Ahmed',)
347>>> myprint ("sadasd",54,[545,2185,12458],{4,56485,488},(544,45,45,4,8,5,4))
348('sadasd', 54, [545, 2185, 12458], set([488, 4, 56485]), (544, 45, 45, 4, 8, 5, 4))
349>>> def myprint(name):
350 print(name)
351>>> myprint("Ahmed",55)
352(19)----------------------------انواع المتغيرات--------------------------Functions الدوال
353>>> name = "Ahmed" *متغير عام*
354>>> x = 55
355
356def myprint():
357 age = 33 *متغير Ù…ØÙ„ÙŠ*
358 print (age)
359>>> 33
360
361Ù…ØÙ„ÙŠ = Local
362عام = Global
363
364def myprint ():
365 global name *وهي دي الدالة الللي بتØÙˆÙ„ المتغير من Ù…ØÙ„ÙŠ Ù„ عام*
366 name = "Ahmed"
367 print (name)
368>>> myprint()
369Ahmed
370>>> print(name)
371Ahmed
372(20)-------------------------تطبيق ع اللي ÙØ§Øª-----------------------Functions الدوال
373def info(name,age,sex):
374 print ("The student name is : ",name)
375 print ("The student age is : ",age)
376 print str(("The student sex is : ",sex))
377
378sname=input("Enter your name : ")
379sage=input("Enter your age : ")
380ssex=input("Enter your six : ")
381
382print ("*"*80)
383print ("press '1' to print more information")
384choice=input("Enter your choice : ")
385if choice=="1":
386 print ("Any thing")
387print("*"*80)
388----------------------------------------------------------------------------------------------------------------------