Lecture 1: Conditionals Flashcards
What are Conditionals? (with ex)
Conditionals allwo you as a programmer to let yout code makes decisions.
Ex: chose the right hand or the left hand
What are the main types of Assignment operators that we used to asl mathematical questions
1- > and < symbols
2- >= “greater than or equal to.”
3- <= “less than or equal to.”
4- == “equals, a single equal sign would assign a value in a string. Double-equal signs are used to compare variables.
5- != denotes “not equal to.
6- Conditional statements
elif is a python keyword that literally saying
if the previous conditions were not true, then try this condition. in other words, it allows the program to make less decisions
What is the job of or?
or is a type of Python Logical or Boolean Operators (عوامل) that allows your program to decide between one or more options
ex:
if x < y or x > y :
print(“x is not equal to y”)
What is the job of and?
and is a type of Python Logical or Boolean Operators that ensure all of the Conditions (شروط) are true
ex:
if score >= 90 and score <= 100:
print(“Grade: A”)
One of the most common ways to improve our code is?
by asking fewer questions. This makes our program easier to read and far more maintainable in the future.
in terms of programming we use the % symbol differently by?
The modulo % operator in programming allows us to see if two numbers divide evenly (بالتساوي) or divide and have a remainder (باقي)
For example, 4 % 2 would result in zero because it evenly divides. However, 3 % 2 does not divide evenly and would result in a number other than zero
What is the job of match statements?
match statements can be used to conditionally run code that matches or connects certain values using “cases”
What does case _ mean?
we use the _ symbol in the last case which will match with any input, resulting in similar behavior as an else statement
How can we check for multiple values in the same case statement?
we use a single vertical bar |
ex:
match name:
case “Harry” | “Hermione” | “Ron”:
print(“Gryffindor”)
What is the control flow?
It is the order in which code commands are executed
هو الترتيب الذي يتم فيه تنفيذ الأوامر البرمجية