الفصل الأول

ملخص الدرس الثالث وحدة ثانية والدرس الأول وحدة ثالثة كمبيوتر صف عاشر فصل أول

ملخص الدرس الثالث وحدة ثانية والدرس الأول وحدة ثالثة كمبيوتر صف عاشر فصل أول

مرفق لكم ملخص الدرس الثالث وحدة ثانية والدرس الأول وحدة ثالثة كمبيوتر صف عاشر فصل أول مناهج الامارات

معلومات المذكرة

  • نوع الملف: ملف تلخيص
  • المادة: حاسوب
  • الصف: العاشر
  • الفصل الدراسي: الفصل الاول
  • صيغة الملف: pdf متاح للتحميل

 صندوق تحميل الملف

[ Computer Science Grade 10 Adv. – Term ]

Repetition

The statements used to repeat code are called loops

تكرار لعدد غير معلوم من while loop

كرار لعدد من المرات for loop

For loops

For loop to repeat a code block a set number of times

 

 

 

 

 

 

Do I need to go to school today
for Day in 1, 2, 3, 4, 5
print (“Wake up and go to school”)
print(“I miss school.”)

5 times
Once
Because the ‘I miss school’ is not part of the for loop

(b) You used the Day variable as a loop counter only. You can use this variable in the code block under the for loop

Do I need to go to school today?
for day in 1, 2, 3, 4, 5
print(“Today is: “, day) print (“Wake up and go to school”)
print (“I miss school.”)

Run the code and explain where the number of the day is coming from.

It is coming from the list of numbers in the for statement

You can use the counter variable in calculations as part of the for loop.
Suppose you wanted to count the number of hours spent in school. You can add a couple of lines to the code to calculate how many hours you have spent in school. The code below assumes that you spend five hours in school each day

HoursInSchool = 0
for Day in 1, 2, 3, 4, 5:
print(“Today is: “, Day) print(“Wake up and go to school.”) Hoursin School – Day * 5 print(“We have spent “, HoursinSchool, “hours in school.”)
print(“I miss school”)

(c) Now change the code to print the number of hours left before the weeke
for Day in 5,4,3,2,1:
print(“Today is”, Day) HoursLeft = Day * 5 print(“Hours left:”, Hours Left)

(d) Change the ‘1, 2, 3, 4, 5’ to ‘5, 4, 3, 2, 1. Explain what happens. Do you need to change the calculation or the message?
Only the message and variable name should be changed, the calculation is the same.

(e) Finally, change the list toʻ-5, -4,-3, -2,-2. What happens?
The results are meaningless. Be careful how you select your list!

[1 Computer Science Grade 10 Adv. – Term ]

Complex problems become smaller easier ones

Function
Functions
? Do you remember those? What we call them

) print (  input  )  int      ) float

Introduction to functions

Functions are a way to organize code •

They are used to divide a problem into smaller ones that are easier to manage •

You can use them as building blocks for a full solution •

inputs   ⇒   processing   ⇒   outputs

Example: design a function add two numbers

Function name  Inputs (parameters)

def keyword to define function

Function code indented

output

: def pwChecker(password)
: if password == 112233 
correct = True
else:
correct = False
return correct

———————————

def encryptor(message, key):
cipherText = “”
for eachChar in message:
cipherText = cipherText + chr(ord(eachChar) + key)
return cipherText

User-defined functions: These are the functions we create in our code

 Imported or external functions: These are functions that are a part of different modules. You can use them after importing the module or part of the module into your code

.  Built-in functions: These are external functions which are part of the Python interpreter like print()or input(). They can be used without importing

def calcarea ( )

def add ( )

External functions
math (  )
random (  )

Call functions and reuse code written by others

To reuse code from other developers, you must import the module. A module is a collection of related functions

from math import *
x = sqrt(16)

There are other functions available from the math module which include

Function ceil(x)
Description returns the smallest integer greater than or equal to x

Function fabs(x)
Description returns the absolute value of x

Function  factorial(x)
Description  returns the factorial of x

Function   floor(x)
Description   returns the largest integer less than or equal to x

Function   exp(x)
Description  returns e to the power of x

Function   log10(x)
Description  returns the base-10 logarithm of x

Function  pow(x, y)
Description  returns x raised to the power y

Function  sqrt(x)
Description  returns the square root of x

Function  cos(x)
Description  returns the cosine of x

Function  sin(x)
Description  returns the sine of x

Function  tan(x)
Description  returns the tangent of x

Function  degrees(x)
Description  converts angle x from radians to degrees

Function  radians(x)
Description  converts angle x from degrees to radians

Function  pi
Description  mathematical constant equal to 3.14159

The random module is another example of a useful module. The random module contains a function that can give you random numbers

. from random import * x = randint (5, 20) print(“x = “, x)

(a) Run the code below a few times and describe the results.

from random import *
number = randint(1, 100) print(number)

A different number between 1 and 100 is printed each time

(b) State one advantage and one disadvantage of importing and using functions from other modules

Advantage: Saves tim
Disadvantage: Need to understand how it works

(C) Import and call the sqrt() math function to calculate the distance between two Cartesian coordinates (2.3) and (10,50).

from math import sqrt
dist =sqrt((50-3)**2 + (10-2)**2)
print(dist)

(d) Import and call a function xyz() which takes an integer from a module called abc.

from abc import xyz xyz(20)

(e) Write the code to import and call a function from the datetime module to print the current date and time. You need to carry out your own research to find the right function to call

Homework(search)

In Design code to import and call two functions from the math module to convert angles from degrees to radians, and radians to degrees. Get the angle values from the user.

from math import radians, degrees
angle = input(“Enter the angle>”)
angle = float(angle)
conversion = input(“Enter 1 to change from deg to rad and 2 for rad to deg”)

if conversion == “1”:
print(angle, “degrees = “,radians(angle), “radians.”)
elif conversion == “2”: print(angle,
“radians = “,degrees(angle), “degrees.”)
else: print(“Error!.”)

تصفح أيضا:
زر الذهاب إلى الأعلى