AI & IOT in Sport: Coding For Innovation - Basic Python 2 – SCOPES-DF

Lesson Details

Age Ranges *
18+,
Fab Tools *
Author
Additional Contributors

Author

Studio 5
Studio 5
Other
In line with the Ministry of Communications and Information Technology’s Digital Youth Strategy, STUDIO 5 is mainly aimed at nurturing youth as digital learners by sharpening their 21st century learning skills, as they develop in an all-pervasive digital environment. In… Read More

Summary

This workshop aims to teach participants Python coding and its fundamentals, using Python programming language. Which includes Python Built-In libraries, Python External Libraries, how to, install them, access their documentation for better understanding, check their functions and how/where to use them. In addition participants will have an “Open-Eye” on many different aspects of Python coding, and most of the area where Python excels.

What You'll Need

Projector/Screen, Laptop, Internet Access

 

Lesson Materials:

Presentation

Lesson Plan English

Lesson Plan Arabic

Lesson Materials

Learning Objectives

  • Know the difference between functions, methods, packages, and modules.
  • Understand the purpose and benefits of using Python’s standard and third-party libraries.
  • Using Matplotlib to visualize datasets and model results
  • Learn how to import and use modules and packages effectively within a program.
  • Be able to use and enhance code reusability.
  • Understand how to use tools like pip to install and manage external libraries.
  • What is Python Built-In Libraries.
  • What is Python External Libraries.
  • How to install/check/manage/use Libraries.
  • How to create User-Defined Functions and use it.
  • How to reduce/eliminate code redundancy
  • How to analyse/manipulate Data
  • How to Plot Data

 

Reflection

This session depends a lot on discussion and student input and work.

The Instructions

Presentation

A quick introduction about us and a way to break the Ice with the participant in order to engage with them in indirect way just to make a conversation and then a question to start the session. A quick recap on Session "Python Basic 1"

Introduction & Icebreaking

Introduce yourself and Studio5. 

A quick recap over the Python 1 session (Ice breaking).

 

Presentation :

1 – We will have a Quick Code Recap.

ask quick questions about: Variables, Lists, Loops, If-Else Statements.

 

2 – How to import built-in libraries. 

 

Math Library and Functions – Built-In Library

 

Python has also a built-in module called math, which extends the list of mathematical functions.

To use it, you must import the math module only once in the Python page: import math

 

تحتوي لغة بايثون أيضًا على وحدة مدمجة تُسمى math، تُوسّع قائمة الدوال الرياضية. لاستخدامها، يكفي استيراد وحدة math مرة واحدة فقط في صفحة بايثون: import math

 

Now you can use all the Built-In Math function that Python provides.

 

الآن يمكنك استخدام جميع وظائف الرياضيات المدمجة التي يوفرها بايثون.

 

 

 

3 – How to use built-in libraries.

 

import math

 

aRes = math.sqrt(50)

 

print(“Result as String is: “+ str(aRes))

print(“Result as Integer is: “+ str(int(aRes)))

 

math.sqrt(InputNumber)

This will give the Square Root value of any provided number

 

Add the following chunk of code to your previous code

 

print(“Result as Floor is: “+ str(math.floor(aRes)))

print(“Result as Ceiling is: “+ str(math.ceil(aRes)))

 

Result Floor is: 7

Result Ceiling is: 8

 

Right-Click on “math

Then “Go To” -> “Implementation

You will get the “math.py” file that contains all the math library built-in functions.

 

انقر بزر الأيمن على “math” ثم “Go To” -> “Implementation” ستحصل على ملف “math.py” الذي يحتوي على جميع الدوال المدمجة في مكتبة الرياضيات.

 

 

 

 

input() function reads data that the user entered on the keyboard.

تقوم الدالة  ()input بقراءة البيانات التي أدخلها المستخدم على لوحة المفاتيح.

 

Usually, we create a variable to store the user data input so we can use it later on.

عادةً، نقوم بإنشاء متغير لتخزين بيانات المستخدم المدخلة حتى نتمكن من استخدامها لاحقًا.

 

Try this code: 

جرب هذا الكود:

 

theUserName = input(“Enter Your Name:”)

print(“Hello ” + theUserName)

 

zResult = input(Enter a number: )

print(math.ceil(math.sqrt(int(zResult))))

 

 

 

 

 

 

4 – How to import External libraries. 

 

Basic Installation with pip from the Terminal:

 

pip install

 

Example:

pip install matplotlib

 

Write:

pip install matplotlib

 

And press ENTER 

 

اكتب: 

pip install matplotlib 

 

ثم اضغط على مفتاح (Enter).

 

 

 

5 – How to use External libraries.

 

External Libraries – matplotlib Test

 

Draw a graph from given data – Multi lines, 3 points

ارسم مخططًا بيانيًا من البيانات المعطاة – خطوط متعددة، 3 نقاط

 

 

import matplotlib.pyplot as plt

x1 = [1,2,3]

y1 = [2,4,1]

plt.plot(x1, y1, label = “line 1”)

 

x2 = [1,3,4]

y2 = [4,1,3]

plt.plot(x2, y2, label = “line 2”)

 

plt.xlabel(‘x – axis’)

plt.ylabel(‘y – axis’)

plt.title(‘TWO lines on same graph!’)

 

plt.legend()

plt.show()

 

 

 

 

6 – How to create User-Defined functions.

 

 

 

 

 

The function do_abc(x) in details:

 

  • def means define, used to create a function
  • do_abc is the name of the function
  • (x) is the value that we give to the function
  • aResult is where we will store the value of calculation
  • return every function have a return. In this case it is aResult 

 

def do_abc(x):

   aResult = x*2/5+34

   return aResult

 

 

aValue = do_abc(75)

 

print(“The result is”, aValue)

 

شرح الدالة do_abc(x) بالتفصيل:

 

  • def تعني تعريف دالة.
  • do_abc هو اسم الدالة.
  • (x) هي القيمة التي نمررها للدالة.
  • aResult هو المكان الذي نخزن فيه نتيجة العملية الحسابية.
  • return لكل دالة قيمة مُعادة، وفي هذه الحالة هي aResult.

 

 

 

Lesson Feedback

Contact us

Having trouble? Let us know by completing the form below. We'll do our best to get your issues resolved quickly.

"*" indicates required fields

This field is for validation purposes and should be left unchanged.
Name*
Email*
?