Lecture 0: Functuions and variables Flashcards
What are functions?
Functions are verbs or actions that the computer or computer language will already know how to perform
What is the difference between parameter and argument?
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
What is the meaning of = sing in terms of programming?
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
We could say that Pseudocode is a kind of?
a comment that becomes a special type of to-do list, especially when you don’t understand how to accomplish a coding task
In terms of programming in Python what is the simplest way to multiple arguments?
We can use a comma , –> print(“hello, “ , name)
What is a string? and how we type it in Python?
A string, known as a str in Python, and it is a sequence of text or arrays of characters
What is the benefit of reading programming documents?
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 can we write “ “ as a part of our tex?
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" “)
What is the job of f here:
print( f “ hello, {name} “ )
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
Expline this code:
name = name.strip()
name = name.title()
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()
Integer is a data type that represents? and how we call it in python?
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
What is the bug in this pice of code:
z = x + y
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
Float is a data type that represents?
a real number that has a decimal point (فاصلة عشرية), such as 0.52
What is the job of round function?
Round (تقريب) the total resultant to the nearest integer or real number
What shuold we write to format the total resultant of long numbers (وضع فواصل على الالاف مثل 1,000)
We can use f-string:
print ( f “ { z: , } “ )
How can we round floating point values in the division process (قسمة) to the nearest two decimal points using Python code?
z = round( x / y , 2 )
or we can use the f-string:
z = x / y
print( f “ { z : .2 f } “ )
How can we round floating point values in the division process (قسمة) to the nearest two decimal points using Python code?
z = round( x / y , 2 )
or we can use the f-string:
z = x / y
print( f “ { z : .2 f } “ )
How can we create our own function in python?
DEF your function’s name (parameter for the function to take) :
explain your function here
*الاحرف الكابيتل هي امر بايثون والباقي شرحي
How to add a default value to your own function?
world is the default value here
add it simply to your parameter like: def hello( to = "world" ):
Why do we use the main function in python?
it works as a starting point for any program and all the variables inside it are local, while those outside it are global
Why do we use return values?
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