diff --git a/lessons/beginners-en/and-or/index.md b/lessons/beginners-en/and-or/index.md index 4792e21893..c67c14d175 100644 --- a/lessons/beginners-en/and-or/index.md +++ b/lessons/beginners-en/and-or/index.md @@ -1,34 +1,33 @@ # *Or* & *and* -In addition to the operators that we saw in the Comparison lesson, we will now add 3 more logical (Boolean) operators to the table: +بالإضافة إلى المشغلين (operators) الذين رأيناهم في درس المقارنة ، سنضيف الآن 3 مشغلات منطقية (بوليانية) (boolean) أخرى إلى الجدول: - - - + + + - + - + - +
SymbolExampleDescriptionالرمزمثالوصف
and x and yTrue if both operands are trueصحيح إذا كان كلا العاملين صحيحًا
or x or yTrue if either operand is trueصحيح إذا كان أحد العاملين صحيحًا
not not xTrue if the operand is false
- (it negates the operand)
صحيح إذا كان العاملان خاطئًا
+ (إنه ينفي العامل)
- ```python # This program gives naive life advice. @@ -66,8 +65,8 @@ else: ``` > [note] -> What happens if you answer something other than "Yes" or "No"? +> ماذا يحدث إذا أجبت بشيء آخر غير "نعم" أو "لا"؟ > -> The variables `happy` and `rich` won't be set, and later when they are needed, the program will end with an error. +> لن يتم تعيين المتغيرين `happy` و `rich` ، وفي وقت لاحق عندما تكون هناك حاجة إليهما ، سينتهي البرنامج بـ خطأ. > -> We will learn how to handle errors [next time]({{ lesson_url('beginners-en/exceptions') }}). +> سنتعلم كيفية التعامل مع الأخطاء [في المرة القادمة]({{ lesson_url('beginners-en/exceptions') }}). \ No newline at end of file diff --git a/lessons/beginners-en/and-or/info.yml b/lessons/beginners-en/and-or/info.yml index fbf3d4613b..a1a5bb180b 100644 --- a/lessons/beginners-en/and-or/info.yml +++ b/lessons/beginners-en/and-or/info.yml @@ -1,6 +1,7 @@ title: Or & and style: md attribution: + - Translated by Mussab Abdalla - Translated by Alexandru Dumitru - | Originally written by Petr Viktorin, 2014-2017 for [PyLadies CZ]. diff --git a/lessons/beginners-en/comparisons/index.md b/lessons/beginners-en/comparisons/index.md index cab0523cc0..6dacd69316 100644 --- a/lessons/beginners-en/comparisons/index.md +++ b/lessons/beginners-en/comparisons/index.md @@ -1,73 +1,72 @@ -# Comparisons +# المقارنات (Comparisons) -Do you still remember what an operator is? +هل لا تزال تتذكر ما هو **المشغل (operator)**؟ -In our homework, we learned some basic arithmetic operators. -If we add one more basic operator (`//` for integer division), our list will look like this: +في واجباتنا المنزلية ، تعلمنا بعض مشغلات الحساب الأساسية. +إذا أضفنا مشغل (operator) أساسي واحد آخر (`//` للقسمة الصحيحة) ، فستبدو قائمتنا كما يلي: - - - + + + - + - + - + - +
SymbolExampleDescriptionالرمزمثالوصف
+, -, *, / 1 + 1Basic arithmeticحساب أساسي
- -5Negationالنفي (negation)
//; % 7 // 2; 7 % 2Integer division, remainder of divisionالقسمة الصحيحة ، الباقي من القسمة
** 3 ** 2Power (3 to the power of 2)الأس (3 أس 2)
-Python also has other types of operators. *Comparison* (relational) -operators are used to compare values. -Try out what they do! -(You can try them by using `print()` in your code, -or you can try `python`'s command line.) +يحتوي Python أيضًا على أنواع أخرى من المشغلات (operators). تُستخدم مشغلات *المقارنة* (العلاقية)(relational) لمقارنة القيم. +جرب ما تفعله! +(يمكنك تجربتها باستخدام `()print` في الكود الخاص بك ، +أو يمكنك تجربة سطر أوامر `python`). - - - + + + - + - + - +
SymbolExampleDescriptionالرمزمثالوصف
==, != 1 == 1, 1 != 1equal, not equalيساوي ، لا يساوي
<, > 3 < 5, 3 > 5greater than, less thanأكبر من ، أقل من
<=, >= 3 <= 5, 3 >= 5Greater or equal, less or equalأكبر أو يساوي ، أقل أو يساوي
-Comparison values are called **boolean** values -(after [G. Boole](http://en.wikipedia.org/wiki/George_Boole)). -They are used every time we want to know if something is `True` or `False`. -Boolean types are exactly those two - `True` and `False`. +تسمى قيم المقارنة **قيم منطقية (boolean)** +(نسبة ل[جورج بول](http://en.wikipedia.org/wiki/George_Boole)). +يتم استخدامها في كل مرة نريد فيها معرفة ما إذا كان شيء ما `صواب` أو `خاطئ`. +الأنواع البولينية هي بالضبط هذان - `صواب` و `خاطئ`. -Like all values, `True` and `False` can be assigned to variables: +مثل جميع القيم ، يمكن تعيين `صواب` و `خاطئ` للمتغيرات: ```python true = 1 < 3 # we have to type it in lowercase now, because True is a reserved word in Python @@ -78,20 +77,22 @@ print(false) ``` > [note] -> Note that to test equality, you have to use two equal signs: `3 == 3`. -> One equal sign assigns a value to a variable, and two equal signs -> compare two values (of variables). +> لاحظ أنه لاختبار المساواة ، يجب عليك استخدام علامتي تساوي: `3 == 3`. +> علامة تساوي واحدة تُعيِّن قيمة إلى متغير ، وعلامتا تساوي +> قارن بين قيمتين (من المتغيرات). -True and False -can be used directly in a program. -Just keep an eye on capitalisation. +يمكن استخدام True و False +مباشرة في البرنامج. +فقط انتبه إلى أن وضع الأحرف (capital). ```python print(True) print(False) ``` -## Conditions +## الشروط (Conditions) + + {% if var('pyladies') -%} {% set rootname = 'pyladies' %} @@ -99,7 +100,7 @@ print(False) {% set rootname = 'naucse-python' %} {%- endif %} -Write the following into a new file (e.g. `if.py`): +اكتب ما يلي في ملف جديد (مثل `if.py`): ```python side = float(input('Enter the side of a square in centimeters: ')) @@ -107,18 +108,17 @@ print("The perimeter of a square with a side of", side,"cm is ", side * 4,"cm.") print("The area of a square with a side of", side,"cm is", side * side, "cm2.") ``` -What happens when you enter a negative number? Does the output make sense? +## ماذا يحدث عندما تدخل رقمًا سالبًا؟ هل النتيجة منطقية؟ -As we can see, the computer does exactly what it is told and doesn't -think about context. You have to do that for it. -It would be nice if the program could tell the user who enters -a negative number that they entered nonsense. -How do we do that? +كما نرى ، يقوم الكمبيوتر بما هو مطلوب منه بالضبط ولا يفكر في السياق. عليك أن تفعل ذلك من أجله. +سيكون من الجيد لو تمكن البرنامج من إخبار المستخدم الذي يدخل +رقمًا سالبًا أنهم أدخلوا قيمة غير منطقية. +كيف نفعل ذلك؟ -Let’s try to set a variable that will be `True` when a user enters a positive number. +دعونا نحاول تعيين متغير (variable) يكون `صواب (True)` عندما يدخل المستخدم رقمًا موجبًا. {% filter solution %} - You can set the variable like this: + يمكنك تعيين المتغير variable على النحو التالي: ```python side = float(input('Enter the side of a square in centimeters: ')) @@ -126,8 +126,8 @@ Let’s try to set a variable that will be `True` when a user enters a positive ``` {% endfilter %} -And then we will tell the program to use this variable. -For that purpose we will use the `if` and `else` statements. +ثم سنخبر البرنامج باستخدام هذا المتغير variable. +لهذا الغرض ، سنستخدم عبارات `if` و `else`. ```python @@ -145,32 +145,32 @@ print("Thank you for using the geometric calculator.") ``` -So after `if`, there is a *condition* which is the -expression we'll use for the decision making. -After the condition you must write a colon (`:`). -The colon is followed by the commands to be executed if the condition is `True`. +إذن بعد `if` ، يوجد *شرط* وهو +التعبير الذي سنستخدمه لاتخاذ القرار. +بعد الشرط يجب أن تكتب نقطتين (:). +يتم متابعة النقاط بواسطه الأوامر التي سيتم تنفيذها إذا كان الشرط `صواب True`. -You need to indent the follow-up lines by **4** spaces each after every colon you use in Python. +يجب أن تحتوي الأسطر اللاحقة على مسافة بادئة (indent) بـ **4** مسافات بعد كل نقطتين تستخدمها في Python. -Then on the same level as `if`, write `else` followed by a `colon :`. The next lines -contain the commands that are executed if the condition is `False`, and they must also be indented.
+ثم على نفس مستوى `if` ، اكتب `else` متبوعًا بـ `colon :`. الأسطر التالية +تحتوي على الأوامر التي يتم تنفيذها إذا كان الشرط `خاطئ False` ، ويجب أن تحتوي على مسافة (indent) أيضًا.
-Then you then can write other code, which is not going to be indented and that will be executed every time, because -the `if` statement `code block` has already ended. +يمكنك بعد ذلك كتابة كود آخر ، و بدون مسافة بادئة (indent) وسيتم تنفيذه في كل مرة ، لأنه +انتهى بالفعل `if` statement `code block`. > [note] -> The indentation doesn't need to be 4 spaces, you could use -> 2 or even 11, or you can use the tabulator. The point is that -> within one block of code, the indentation has to be the same. -> So if you are working on some project with someone else, you -> have to agree on indentation for the program -> to be able to run properly. Most of the people -> from the Python community agree on 4 spaces. +> لا يلزم أن تكون المسافة البادئة 4 مسافات ، يمكنك استخدام +> 2 أو حتى 11 ، أو يمكنك استخدام علامة التبويب. النقطة هي أن +> ضمن كتلة كود واحدة ، يجب أن تكون المسافة البادئة هي نفسها. +> لذلك إذا كنت تعمل على مشروع ما مع شخص آخر ، فأنت +> يجب أن تتفق على المسافة البادئة للبرنامج +> لتتمكن من تشغيله بشكل صحيح. معظم الناس +> من مجتمع Python يتفقون على 4 مسافات. -## Other conditional statements +## عبارات شرطية أخرى (Other conditional statements) -Sometimes the `else` statement is not necessary. -The following program does nothing extra if the number is not equal to zero. +في بعض الأحيان لا تكون عبارة `else` ضرورية. +لا يفعل البرنامج التالي أي شيء إضافي إذا لم يكن الرقم مساويًا للصفر. ```python number = int(input('Enter a number, to which I will add 3: ')) @@ -179,11 +179,11 @@ if number == 0: print(number, '+ 3 =', number + 3) ``` -Sometimes several conditions are needed. For this situation, we have the `elif` statement -(combination of `else` and `if`). It's between `if` and `else`. -You can repeat the `elif` keyword after the first `if`, but -only one branch will be executed, to be precise: the first one -where the conditions are met (they are `true`). +في بعض الأحيان تكون هناك حاجة إلى عدة شروط. لهذا الموقف ، لدينا عبارة `elif` +(مزيج من `else` و `if`). إنه بين `if` و `else`. +يمكنك تكرار كلمة `elif` بعد أول `if` ، ولكن +سيتم تنفيذ فرع واحد فقط ، بالتحديد: الأول +حيث تتحقق الشروط (إنها `صواب True`). ```python @@ -202,9 +202,9 @@ else : print('Visitors from the future are not welcomed here!') ``` -## Winter clothing +## ملابس الشتاء (Winter clothing) -The following piece of code is a bit advanced and we won't fully discuss it right now. In order to work with it, you only need to understand that it will load the current temperature in the city of Vienna (written in German as Wien to not confuse with the city Vienna present in the USA) from the internet into a variable: +القطعة التالية من التعليمات البرمجية متقدمة بعض الشيء ولن نناقشها بالكامل الآن. للعمل معها ، تحتاج فقط إلى فهم أنها ستقوم بتحميل درجة الحرارة الحالية في مدينة فيينا (الكتابة باللغة الألمانية Wien لعدم الخلط بينها وبين مدينة فيينا الموجودة في الولايات المتحدة الأمريكية) من الإنترنت إلى متغير variable: ```python from urllib.request import urlopen @@ -212,7 +212,7 @@ url = "https://wttr.in/Wien?format=%t" temperature = int(urlopen(url).read().decode().strip("°C")) ``` -Write a program using `if`, `elif` and `else` which prints whether you will need no jacket, a light jacket or a winter coat depending on the current temperature: +اكتب برنامجًا يستخدم `if` و `elif` و `else` والذي يطبع ما إذا كنت ستحتاج إلى سترة ، أو سترة خفيفة أو معطف شتوي اعتمادًا على درجة الحرارة الحالية: {% filter solution %} @@ -231,9 +231,9 @@ Write a program using `if`, `elif` and `else` which prints whether you will need {% endfilter %} -## Rock paper scissors +## حجر ورقة مقص (Rock paper scissors) -`If`s can be nested - after an `if` and its indentation, there can be other `if`. +يمكن ادراج (nesting) عبارات `if` - بعد عبارة `if` ومسافاتها البادئة (indentation) ، يمكن أن تكون هناك عبارات `if` أخرى. ```python @@ -266,6 +266,5 @@ else: ``` -Yay, your first game! **Congratulations!!!**
-Now we need to overwrite the pc_choice so it will act -randomly. We will talk about how to do this next time. +**تهانينا!!!**
+الآن نريد ان نجعل اختيار الكمبيوتر يعمل بشكل عشوائي. نحتاج إلى تغيير قيمة `pc_choice`. سنناقش كيفية القيام بذلك في المرة القادمة. diff --git a/lessons/beginners-en/comparisons/info.yml b/lessons/beginners-en/comparisons/info.yml index 1a458b952e..ba4ca01311 100644 --- a/lessons/beginners-en/comparisons/info.yml +++ b/lessons/beginners-en/comparisons/info.yml @@ -1,6 +1,7 @@ -title: Comparison +title: المقارنات (Comparisons) style: md attribution: +- Translated by Mussab Abdalla - Translated by Marketa Muzikova and Alexandru Dumitru - | Originally written by Petr Viktorin, 2014-2017 for [PyLadies CZ]. diff --git a/lessons/beginners-en/functions/index.md b/lessons/beginners-en/functions/index.md index 497573058d..df43e2dfb5 100644 --- a/lessons/beginners-en/functions/index.md +++ b/lessons/beginners-en/functions/index.md @@ -1,12 +1,12 @@ -If you would like to do some calculations with the number π (pi), how would you write it? -3.14159265 ? +إذا كنت ترغب في إجراء بعض الحسابات باستخدام الرقم π (pi) ، كيف ستكتبه؟ +3.14159265 ؟ -Python has a lot of built-in features. You don’t have to reinvent the wheel, -you just have to know where to look. +يحتوي Python على العديد من الخصائص المبنية مسبقا. لا تحتاج إلى إعادة العملية كل مرة ، +ما عليك سوى معرفة مكان البحث. -We can access *π* by importing the `math` module. +يمكننا الوصول إلى *π* عن طريق استيراد (import) مكتبة (module) `math`. ```python @@ -15,27 +15,23 @@ from math import pi print(pi) ``` -As you can see, π is a bit hidden. Compared to `print` or `if`, which everyone needs, -not everyone needs `math`. Let's stick with this module for a bit longer. +كما ترى ، فإن π مخفي بعض الشيء. مقارنةً بـ `print` أو `if` ، والتي يحتاجها الجميع ، +لا يحتاج الجميع إلى `math`. دعونا نكتفي بهذه االمكتبة (module) لفترة أطول قليلاً. +## التعبيرات (Expressions) - -## Expressions - -In mathematics we have a lot of different operations that are implemented as -symbols, like + or -. The same symbols are used in Python. +في الرياضيات ، لدينا العديد من العمليات المختلفة التي يتم تنفيذها كرموز ، مثل + أو -. يتم استخدام نفس الرموز في Python. * 3 + 4 * a - b -It's a bit difficult with multiplying and dividing -because you can't write the usual mathematical expression -on your keyboard: +يصعب الأمر قليلاً مع الضرب والقسمة لأنه لا يمكنك كتابة تعبير رياضي معتاد +على لوحة المفاتيح الخاصة بك: * 3 · 4 * ¾ -Mathematicians were inventing more and more complex symbols -that cannot be just as easily replicated by programmers: +اخترع علماء الرياضيات المزيد والمزيد من الرموز المعقدة +والتي لا يمكن بسهولة نسخها بواسطة المبرمجين: * x² @@ -47,22 +43,20 @@ that cannot be just as easily replicated by programmers: * ab * ab -There are even programming languages that need a -special keyboard. But their programs can't be easily -written and they aren't readable. +هناك حتى لغات برمجة تحتاج إلى لوحة مفاتيح خاصة. لأن برامجهم لا يمكن كتابتها بسهولة +وهي غير قابلة للقراءة. > [note] -> For example this is program written in language APL: -> -> +> على سبيل المثال ، هذا برنامج مكتوب بلغة APL: > +> > > ⍎’⎕’,∈Nρ⊂S←’←⎕←(3=T)∨M∧2=T←⊃+/(V⌽”⊂M),(V⊖”⊂M),(V,⌽V)⌽”(V,V←1¯1)⊖”⊂M’ -There are relatively few operators in Python. -And we already know almost half of them! -Some operators are words. -Here are all of them: +هناك عدد قليل نسبيًا من المشغلات (operators) في Python. +وقد عرفنا بالفعل نصفهم تقريبًا! +بعض المشغلات عبارة عن كلمات. +إليك جميعها:
== != @@ -89,26 +83,26 @@ Here are all of them: is is not
-It is clear now that some operations that we want to do in a program -cannot be expressed by these operators. +من الواضح الآن أن بعض العمليات التي نريد القيام بها في البرنامج +لا يمكن التعبير عنها بواسطة هذه المشغلات (operators). -How to deal with this? +كيف تتعامل مع هذا؟ -One way which we have already mentioned is to define the operation in words. +إحدى الطرق التي ذكرناها بالفعل هي تعريف العملية بالكلمات. * x = sin a -And we can write that on our keyboards! -We just have to add parentheses (some editors will do that for us) to make it -clear to what the operation applies: +ويمكننا كتابة ذلك على لوحات المفاتيح الخاصة بنا! +علينا فقط إضافة أقواس (احيانا يقوم المحرر (editor) بذلك نيابة عنا) لجعلها +واضح لما تطبق العملية: ```python x = sin(a) ``` -But first of all you have to *import* `sin`, -in the same way as you already imported `pi`. -So the whole program will look like this: +ولكن أولاً وقبل كل شيء ، يجب عليك *استيراد (import)* `sin` ، +بنفس الطريقة التي استوردت بها `pi` بالفعل. +لذلك سيبدو البرنامج الكامل على النحو التالي: ```python from math import sin @@ -117,32 +111,30 @@ x = sin(1) # (in radian) print(x) ``` -> [warning] Import and files names -> When we want to import modules, we have to pay extra attention -> how we name our own program files. -> If you import the module `math` into your program, your file can't -> have name `math.py` itself. +> [warning] استيراد الملفات و اسمائها (Import and files names) > -> Why? Because if you are importing a module, Python will look first -> into the folder from which you are running the program. -> It will find the file `math.py` and will try to import the `sin` function from there. -> And of course it won't find it. - +> عندما نريد استيراد (import) المكتبات ، يتعين علينا الانتباه بشكل إضافي +> كيف نسمي ملفات البرنامج الخاصة بنا. +> إذا قمت باستيراد الوحدة `math` إلى برنامجك ، فلا يمكن أن يكون لملفك اسم `math.py` نفسه. +> +> لماذا؟ لأنه إذا كنت تستورد وحدة ، فسيبحث Python أولاً +> في المجلد الذي تقوم بتشغيل البرنامج منه. +> سيجد الملف `math.py` وسيحاول استيراد دالة `sin` من هناك. +> وبالطبع لن يجدها. -## Call functions -We call the function by its *name*. +## استدعاء الدوال (Call functions) -The name looks like a variable -– actually, it *is* a variable, the -only difference is that instead of a number or a string, we have a function stored inside. +نستدعي الدالة (function) حسب *اسمها*. -After the name of the function, we have parentheses where we enclose the *argument* -(or *input*) for the function. This is the information which our function will work with. -In our example, `sin()` will calculate the sine +يبدو الاسم وكأنه متغير (variable) - في الواقع ، إنه *متغير (variable)* ، الفرق الوحيد هو أنه بدلاً من رقم أو سلسلة ، +لدينا دالة (function) مخزنة في الداخل. -The *return value* of a function is a value that can be -assigned to a variable. +بعد اسم الدالة (function) ، لدينا أقواس نضع فيها *الوسيطة* +(أو *الإدخال*) للدالة (function). هذه هي المعلومات التي ستعمل بها وظيفتنا. +في مثالنا ، ستقوم `()sin` بحساب الجيب +*القيمة المرجعة* للدالة (function) هي قيمة يمكن تعيينها إلى متغير. ``` function name @@ -152,34 +144,34 @@ assigned to a variable. ▲ ╰┬╯ │ argument │ - ╰── return value + ╰── return value ``` -Or we can use it in other operations: +يمكننا ايضا استخدامها في عملية حسابية: ```python a = sin(1) + cos(2) ``` -Or we can use it in an `if` condition: +او من الممكن استخدامها كشرط تحت `if`: ```python if sin(1) < 3: ``` -Or, even use it as an input for a different function: +او حتى استخدامها كقيمة داخل دالة (function) اخرى : ```python print(sin(1)) ``` -… etc. +و هكذا -### Arguments +### القيم (Arguments) -To some functions, we can pass multiple arguments. An example is `print`, -which prints all its arguments consecutively. We separate the arguments by comma: +يمكننا تمرير عدة قيم (Arguments) إلى بعض الدوال. مثال على ذلك هي `print` ، +التي تطبع جميع القيم المدخلة اليها على التوالي. نفصل بين القيم بفاصلة: ```python print(1, 2, 3) @@ -188,25 +180,23 @@ print(1, 2, 3) ```python print("One plus two equals", 1 + 2) ``` -Some functions do not need any argument, the function `print` is again an example for this. -But we still have to write the parentheses, even if they are empty. -Guess what `print` without arguments will do? +بعض الدوال لا تحتاج إلى أي قيمة ، والدالة print هي مثال آخر على ذلك. +ولكن لا يزال يتعين علينا كتابة الأقواس ، حتى لو كانت فارغة. خمن ماذا ستفعل print بدون قيم؟ ```python print() ``` {% filter solution %} -The function `print` without arguments will print an empty line. +ستقوم الدالة print بدون قيم بطباعة سطر فارغ. -It's exactly following the definition -- the function `print` will write all -its arguments on a line. +يتبع ذلك التعريف تمامًا - ستكتب الدالة print كل +قيمها على سطر. {% endfilter %} -### Functions have to be called - -Be careful to write the parentheses, otherwise, the function is not called. -You will not get the return value, but the function itself! Let’s try the following examples: +عند استدعاء الدوال (Call functions) +كن حذرًا عند كتابة الأقواس ، وإلا فلن يتم استدعاء الدالة. +لن تحصل على قيمة الإرجاع ، ولكن الدالة نفسها! دعنا نجرب الأمثلة التالية: ```python from math import sin @@ -215,18 +205,19 @@ print(sin) print(sin + 1) ``` -### Named arguments +### القيم المسماة مسبقا (Named arguments) -Some functions can also work with *named* arguments. -They are written similarly to the assignment of a variable, with an equals sign, -but inside the parentheses: +يمكن لبعض الوظائف أيضًا العمل مع القيم *المسماة مسبقا*. +يتم كتابتها بطريقة مشابهة لإسناد متغير ، باستخدام علامة مساواة ، +ولكن داخل الأقواس: -For example, the function `print` ends with printing a newline character at the end of a line by default, -but we can change that by using the named argument `end`, and print something else. +على سبيل المثال ، تنتهي وظيفة `print` بطباعة حرف سطر جديد في نهاية السطر بشكل افتراضي ، +ولكن يمكننا تغيير ذلك باستخدام القيمة المسماة `end` ، وطباعة شيء آخر. > [note] -> We have to write this into a .py file to run it because we won't -> be able to see it properly in the interactive console. +> يتعين علينا كتابة هذا في ملف .py لتشغيله لأننا لن نتمكن من ذلك +> لرؤيتها بشكل صحيح في لوحة التحكم التفاعلية. + ```python print('1 + 2', end=' ') @@ -235,24 +226,24 @@ print(1 + 2, end='!') print() ``` -## Useful functions +## دوال مفيدة (Useful functions) -At last, we will look at some basic functions which are built in. -You can also download this -cheatsheet. +أخيرًا ، سنلقي نظرة على بعض الدوال الأساسية المضمنة. +يمكنك أيضًا تنزيل ورقة الغش هذه +cheatsheet. -### Input and output +### المدخلات والمخرجات (Input and output) -We already know these functions. -`print` writes non-named arguments separated by spaces into the output. -It will write a named argument `end` in the end of a line (the default is a newline character). -And another named argument `sep` defines what will be written between each argument (default is a space character). +نحن نعرف هذه الدوال بالفعل. +تقوم `print` بكتابة القيم غير المسماة والمفصولة بمسافات في الإخراج. +سيقوم بكتابة قيمة مسماة `end` في نهاية السطر (الافتراضي (default) هو سطر جديد). +وقيمة مسماة أخرى `sep` تحدد ما سيتم كتابته بين كل قيمة (الافتراضي (default) هو مسافة). > [note] -> We recommend to run the following example -> from a file, not from the Python console. +> نوصي بتشغيل المثال التالي +> من ملف ، وليس من وحدة تحكم Python. ```python print(1, "two", False) @@ -260,26 +251,27 @@ print(1, end=" ") print(2, 3, 4, sep=", ") ``` -The basic function for input is obviously `input`. -It will print the question (or whatever you type in), -collect the input from the user, and return it -as a string. + +**الدالة الأساسية للإدخال هي `input` بشكل واضح.** +ستقوم بطباعة السؤال (أو أي شيء تكتبه) ، +جمع الإدخال من المستخدم ، وإعادته +كـ نص (string). ```python input('Enter input: ') ``` -### Type conversion (type casting) +### تحويل النوع (Type casting) -In case we don’t want to work just with strings, here is a group of -functions that can convert strings to numbers and back. -But what to do when we don't won't to work with a string but, for example, with a number? -There's a group of functions that can help us convert strings to numbers and back. -Each of the three types of variables that we currently know -has a function which takes a value (as an argument) and returns it as a -value of its own type. -For *integers* there's the function `int()`, for *floating points* there's -`float`, and for *strings* there's `str()`. +في حالة عدم رغبتنا في العمل فقط مع النصوص ، فهناك مجموعة من +الدوال التي يمكنها تحويل النصوص إلى أرقام والعكس صحيح. +ولكن ماذا تفعل عندما لا تريد العمل مع نص ولكن ، على سبيل المثال ، مع رقم؟ +هناك مجموعة من الدوال التي يمكن أن تساعدنا في تحويل النصوص إلى أرقام والعكس صحيح. +كل واحد من الأنواع الثلاثة *للمتغيرات* التي نعرفها حاليًا +لديه دالة تأخذ قيمة وتعيدها كـ +قيمة من نوعها الخاص. +بالنسبة إلى *الأعداد الصحيحة* ، توجد الدالة `()int` ، وبالنسبة إلى *الأعداد العشرية* ، هناك +`float` ، وبالنسبة إلى *النصوص* ، هناك `()str`. ```python @@ -288,7 +280,7 @@ float(x) # conversion to real number str(x) # conversion to string ``` -Examples: +امثلة: ```python 3 == int('3') == int(3.0) == int(3.141) == int(3) @@ -297,7 +289,7 @@ Examples: '3' == str(3) == str('3') '3.141' == str(3.141) == str('3.141') ``` -But not all conversions are possible: +ولكن ليست كل التحويلات ممكنة: ```python int('blablabla') # error! @@ -305,21 +297,21 @@ float('blablabla') # error! int('8.9') # error! ``` -We will tell you how to deal with errors at some other time. +سنخبرك بكيفية التعامل مع الأخطاء في وقت آخر. -### Mathematical functions +### الدوال الرياضية (Mathematical functions) -Maths is sometimes useful so let's have a look how to work -with numbers in Python :) +الرياضيات مفيدة في بعض الأحيان لذلك دعونا نلقي نظرة على كيفية العمل +مع الأرقام في Python (: -There is one mathematical function which is always available: +هناك دالة رياضية واحدة متاحة دائمًا: ```python round(number) # rounding ``` -Lots of others are imported from the `math` module: +يتم استيراد الكثير من الدوال الأخرى من مكتبة(module) `math` : ```python from math import sin, cos, tan, sqrt, floor, ceil @@ -333,28 +325,26 @@ floor(angle) # rounding down ceil(angle) # rounding up ``` -### Help +### المساعدة (Help) -There are some more functions that help programmers: -You can get help regarding a specific function from the program -itself (or Python console) by using the help function. -It's sometimes useful even for beginners, but if -not - use Google. +هناك بعض الدوال الأخرى التي تساعد المبرمجين: +يمكنك الحصول على مساعدة حول دالة معينة من البرنامج نفسه +(أو وحدة تحكم (console) Python) باستخدام دالة المساعدة (help function). +غالبًا ما يكون مفيدًا حتى للمبتدئين ، ولكن إذا لم يكن كذلك - فاستخدم Google. -Help will be shown, depending on your operating system, -either in the browser or right there in the terminal. -If the help is too long for the terminal, you can browse pages using - (, , -PgUp, PgDn) and you can get "out" by pressing the -key Q (like *Quit*). +سيتم عرض المساعدة ، حسب نظام التشغيل الخاص بك ، +إما في المتصفح أو مباشرة في المحطة (terminal). +إذا كانت المساعدة طويلة جدًا بالنسبة للمحطة(terminal) ، فيمكنك استعراض الصفحات باستخدام +  (, , +PgUp, PgDn) ويمكنك الخروج من خلال الضغط على المفتاح Q (مثل *إنهاء*). -You can get help for print like that: +يمكنك الحصول على مساعدة لـ `print` مثلا هكذا: ```python help(print) ``` -You can also get help for a whole module:. +يمكنك أيضًا الحصول على المساعدة للمكتبة (module) بأكملها: ```python import math @@ -364,8 +354,8 @@ help(math) ### Random -Last but not least, we will look at two functions from -`random` which are very useful for games. +أخيرًا وليس آخرًا ، سنلقي نظرة على دالتين من +`random` مفيدة جدًا للألعاب. ```python from random import randrange, uniform @@ -374,9 +364,9 @@ randrange(a, b) # random integer from a to b-1 uniform(a, b) # random float from a to b ``` -Beware that the randrange(a, b) never returns b. -If we need to randomly choose between 3 options, use randrange(0,3) -which returns 0, 1, or 2: +احذر من أن randrange(a, b) لا ترجع القيمة `b` أبدًا. +عندما نحتاج إلى الاختيار بشكل عشوائي بين 3 خيارات ، فاننا نستخدم `randrange(0,3)` +الذي يقترح 0 أو 1 أو 2: ```python @@ -392,13 +382,13 @@ else: # 2 ``` > [note] -> Remember that when you want to import the `random` module, you can't -> name your own file `random.py`. +> تذكر أنه عندما تريد استيرادالمكتبة `random` ، لا يمكنك تسمية ملفك الخاص `random.py`. + +### والمزيد -### And more... -There are a lot more functions within Python itself, -although you probably won't understand them at the beginning. -All of them are in the Python documentation, e.g.: -built-in, -maths. +هناك العديد من الدوال الأخرى المضمنة في بايثون نفسها ، +على الرغم من أنك ربما لا تفهمها في البداية. +يمكن العثور عليها جميعًا في وثائق Python ، على سبيل المثال: +الدوال المضمنة, +مكتبة الرياضيات. \ No newline at end of file diff --git a/lessons/beginners-en/functions/info.yml b/lessons/beginners-en/functions/info.yml index 5a712f1948..2b37c9d9e0 100644 --- a/lessons/beginners-en/functions/info.yml +++ b/lessons/beginners-en/functions/info.yml @@ -1,6 +1,7 @@ -title: Functions +title: الدوال (Functions) style: md attribution: +- Translated by Mussab Abdalla - Translated by Marketa Muzikova and Alexandru Dumitru - | Originally written by Petr Viktorin, 2014-2017 for [PyLadies CZ]. diff --git a/runs/2024/pyladies-en-vienna-2024-spring/info.yml b/runs/2024/pyladies-en-vienna-2024-spring/info.yml index babdd765ac..ef5afc447c 100644 --- a/runs/2024/pyladies-en-vienna-2024-spring/info.yml +++ b/runs/2024/pyladies-en-vienna-2024-spring/info.yml @@ -88,19 +88,19 @@ plan: - lesson: beginners-en/lesson-2-homework type: homework -# - title: Conditions, modules and functions -# slug: loops -# date: 2024-04-02 -# materials: -# - lesson: beginners-en/comparisons -# - lesson: beginners-en/and-or -# - lesson: beginners-en/functions -# - title: Basics cheatsheet -# url: https://github.com/ehmatthes/pcc/releases/download/v1.0.0/beginners_python_cheat_sheet_pcc.pdf -# type: cheatsheet -# - title: Homework -# url: https://docs.google.com/document/d/1HsKbAt6DAH8uQYJUR8UB8sOFvzgUUr_WeZwB6cb9lcA -# type: homework + - title: الشروط (Conditions)، الدوال (functions) و المكتبات (modules) + slug: loops + date: 2025-01-05 + materials: + - lesson: beginners-en/comparisons + - lesson: beginners-en/and-or + - lesson: beginners-en/functions + - title: Basics cheatsheet + url: https://github.com/ehmatthes/pcc/releases/download/v1.0.0/beginners_python_cheat_sheet_pcc.pdf + type: cheatsheet + - title: Homework + url: https://docs.google.com/document/d/1cTDxe2Wy1zrS_mXwxheUT4iOZo26-8Y2VqiBLSYOiYQ + type: homework # - title: Loops, for and while # date: 2024-04-09