Lecture 0: Functuions and variables Flashcards

1
Q

What are functions?

A

Functions are verbs or actions that the computer or computer language will already know how to perform

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between parameter and argument?

A

PARAMETER → PLACEHOLDER (This means a placeholder belongs to the function naming and be used in the function body) ex: the Name variable

ARGUMENT → ACTUAL VALUE (This means an actual value that is passed by the function calling) ex: the value itself like Zain

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the meaning of = sing in terms of programming?

A

equal sign literally assigns (تعيين) what is on the right to what is on the left
ex: the value returned by input(“What’s your name? “) Is assigned to name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

We could say that Pseudocode is a kind of?

A

a comment that becomes a special type of to-do list, especially when you don’t understand how to accomplish a coding task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In terms of programming in Python what is the simplest way to multiple arguments?

A

We can use a comma , –> print(“hello, “ , name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a string? and how we type it in Python?

A

A string, known as a str in Python, and it is a sequence of text or arrays of characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the benefit of reading programming documents?

A

Functions take arguments that influence their behavior and this means that functions automatically include a piece of code inside of them
ex: creating a new line by default in print function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can we write “ “ as a part of our tex?

A

using the backslashes tells the compiler that the following character should be considered a quotation mark in the string and avoid a compiler error
ex: print(“hello, "friend" “)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the job of f here:

print( f “ hello, {name} “ )

A

Python f strings embed expressions into a string literally. You can use f strings to embed variables, strings, or the results of functions into a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Expline this code:
name = name.strip()
name = name.title()

A

We have our variable on the left side and methods on the right side

  • Strip: remove whitespace from the string
  • Title: capitalize the first letter of each word

or maybe we could simplify it to:
name = input( “What’s your name? “ ).strip() .title()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Integer is a data type that represents? and how we call it in python?

A

data type which represents real numbers that do not have fractional values (كسور أو فواصل عشرية)

Ex: 5, 0, 321, and -17 are all integers, while 5.2, -101.88, and 3⁄4 are not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the bug in this pice of code:

z = x + y

A

it will show us the two numbers next to each other instead of calculating them
ex: 2 + 2 = 22
because + sing desing to concatenates two strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Float is a data type that represents?

A

a real number that has a decimal point (فاصلة عشرية), such as 0.52

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the job of round function?

A

Round (تقريب) the total resultant to the nearest integer or real number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What shuold we write to format the total resultant of long numbers (وضع فواصل على الالاف مثل 1,000)

A

We can use f-string:

print ( f “ { z: , } “ )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can we round floating point values in the division process (قسمة) to the nearest two decimal points using Python code?

A

z = round( x / y , 2 )

or we can use the f-string:
z = x / y
print( f “ { z : .2 f } “ )

16
Q

How can we round floating point values in the division process (قسمة) to the nearest two decimal points using Python code?

A

z = round( x / y , 2 )

or we can use the f-string:
z = x / y
print( f “ { z : .2 f } “ )

17
Q

How can we create our own function in python?

A

DEF your function’s name (parameter for the function to take) :
explain your function here

*الاحرف الكابيتل هي امر بايثون والباقي شرحي

18
Q

How to add a default value to your own function?

A

world is the default value here

add it simply to your parameter like:
def hello( to = "world" ):
19
Q

Why do we use the main function in python?

A

it works as a starting point for any program and all the variables inside it are local, while those outside it are global

20
Q

Why do we use return values?

A

n = number

We use them to let our functions send Python objects back to the user
and we can use them to accomplish further مثل التربيع:

def square(n):
    return n * n