مراجعة العمليات الرياضية في Python بشكل سهل وممتع

سلسلة المراجعة: العمليات الرياضية في بايثون بطريقة سهلة وممتعة! :tada:

هل تتذكر أيام المدرسة وكيف كانت العمليات الرياضية تبدو معقدة؟ حسنًا، مع بايثون، الأمور أبسط بكثير! دعونا نلقي نظرة على العمليات الرياضية (Arithmetic Operations) ونرى كيف يمكننا استخدامها بطريقة سهلة ومسلية.

:rocket: العمليات الأساسية في بايثون:

في بايثون، يمكنك إجراء عمليات رياضية بكل سهولة باستخدام رموز بسيطة جدًا. وإليك أشهر العمليات:

  1. الجمع (+):

    • لإضافة رقمين أو أكثر.
    • :desktop_computer: مثال:
    result = 5 + 3
    print(result)  # النتيجة ستكون 8
    
  2. الطرح (-):

    • لطرح الأرقام من بعضها.
    • :desktop_computer: مثال:
    result = 10 - 4
    print(result)  # النتيجة ستكون 6
    
  3. الضرب (*):

    • لضرب الأرقام ببعضها.
    • :desktop_computer: مثال:
    result = 7 * 6
    print(result)  # النتيجة ستكون 42
    
  4. القسمة (/):

    • لتقسيم الأرقام، والنتيجة تكون دائمًا عدد عشري (float).
    • :desktop_computer: مثال:
    result = 9 / 3
    print(result)  # النتيجة ستكون 3.0
    
  5. القسمة للحصول على الباقي (%):

    • للحصول على الباقي بعد القسمة.
    • :desktop_computer: مثال:
    result = 10 % 3
    print(result)  # النتيجة ستكون 1
    
  6. الأس ():**

    • لرفع الرقم إلى قوة معينة.
    • :desktop_computer: مثال:
    result = 2 ** 3
    print(result)  # النتيجة ستكون 8 (2 مرفوعة للأس 3)
    
  7. التقسيم التام (//):

    • للحصول على النتيجة بدون أي كسور بعد القسمة (قسمة صحيحة).
    • :desktop_computer: مثال:
    result = 10 // 3
    print(result)  # النتيجة ستكون 3
    

:dart: متى نستخدم هذه العمليات؟

  • الجمع: عندما تريد إضافة قيم معًا مثل الأعداد أو المتغيرات.
  • الطرح: عندما تحتاج إلى معرفة الفرق بين رقمين.
  • الضرب: إذا كنت ترغب في حساب نتائج مثل المساحة أو السعر الإجمالي لعدد من المنتجات.
  • القسمة: للحصول على ناتج القسمة العادي أو لتقسيم الموارد بالتساوي.
  • الباقي: يمكن استخدامه لمعرفة إذا كان الرقم فرديًا أم زوجيًا (باستخدام 2).
  • الأس: لحساب القوة مثل مضاعفة مبلغ معين أو لحساب الأسطح في الهندسة.
  • التقسيم التام: لاستخراج الأعداد الصحيحة بدون الفواصل العشرية.

:smile: خاتمة:

العمليات الرياضية في بايثون بسيطة ومباشرة. باستخدام هذه العمليات الأساسية، يمكنك تنفيذ العديد من الحسابات بسهولة في مشاريعك البرمجية. هل جربت كتابة معادلات باستخدام بايثون؟ الأمر ممتع جدًا، فجرّب الآن! :computer:


English Version: Arithmetic Operations in Python - Fun and Simple! :tada:

Remember those school days when math operations seemed complicated? Well, with Python, things are way easier! Let’s dive into Arithmetic Operations and see how we can use them in a fun and straightforward way.

:rocket: Basic Arithmetic Operations in Python:

In Python, you can perform arithmetic operations with very simple symbols. Here are the most common ones:

  1. Addition (+):

    • Adds two or more numbers.
    • :desktop_computer: Example:
    result = 5 + 3
    print(result)  # Output: 8
    
  2. Subtraction (-):

    • Subtracts numbers.
    • :desktop_computer: Example:
    result = 10 - 4
    print(result)  # Output: 6
    
  3. Multiplication (*):

    • Multiplies numbers.
    • :desktop_computer: Example:
    result = 7 * 6
    print(result)  # Output: 42
    
  4. Division (/):

    • Divides numbers, the result is always a float.
    • :desktop_computer: Example:
    result = 9 / 3
    print(result)  # Output: 3.0
    
  5. Modulo (%):

    • Gives the remainder after division.
    • :desktop_computer: Example:
    result = 10 % 3
    print(result)  # Output: 1
    
  6. Exponentiation ()**:

    • Raises a number to the power of another.
    • :desktop_computer: Example:
    result = 2 ** 3
    print(result)  # Output: 8
    
  7. Floor Division (//):

    • Performs division and discards the decimal part.
    • :desktop_computer: Example:
    result = 10 // 3
    print(result)  # Output: 3
    

:dart: When to Use These Operations?

  • Addition: Whenever you need to add values like numbers or variables.
  • Subtraction: When you want to find the difference between two numbers.
  • Multiplication: Useful for calculating things like area or total price for a quantity of items.
  • Division: To get a regular division result or share resources equally.
  • Modulo: Often used to check if a number is odd or even (using 2).
  • Exponentiation: For calculating powers like squaring numbers or geometric calculations.
  • Floor Division: To get whole numbers without decimal points after division.

:smile: Conclusion:

Arithmetic operations in Python are easy and straightforward. With these basic operations, you can execute many calculations effortlessly in your coding projects. Have you tried writing equations using Python? It’s super fun, so give it a go now! :computer:

3 إعجابات