3rd Quarter (COMP10) (PHINMA)

Cards (81)

  • What logical condition checks for equality in Python?
    a == b
  • What logical condition checks for inequality in Python?
    a != b
  • What is the Python condition for less than?
    a < b
  • What is the Python condition for less than or equal to?
    a <= b
  • What is the Python condition for greater than?
    a > b
  • What is the Python condition for greater than or equal to?
    a >= b
  • In what contexts can Python conditions be used?
    In "if statements" and loops
  • How is an "if statement" initiated in Python?
    Using the if keyword
  • What will the following code print? `if b > a: print("b is greater than a")` when a = 33 and b = 200?
    b is greater than a
  • What does Python rely on to define scope in the code?
    Indentation
  • What error occurs if an if statement is not properly indented?
    IndentationError
  • What does the `elif` keyword do in Python?
    Checks another condition if previous ones are false
  • What will the following code print? `if b > a: print("b is greater than a") elif a == b: print("a and b are equal")` when a = 33 and b = 33?
    a and b are equal
  • What does the `else` keyword do in Python?
    Catches any conditions not met by previous statements
  • What will the following code print? `if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b")` when a = 200 and b = 33?
    a is greater than b
  • What will the following code print? `if b > a: print("b is greater than a") else: print("b is not greater than a")` when a = 200 and b = 33?
    b is not greater than a
  • How can you write a short-hand if statement in Python?
    Using `if condition: action`
  • What will the following code print? `if a > b: print("a is greater than b")` when a = 200 and b = 33?
    a is greater than b
  • How can you write a short-hand if-else statement in Python?
    Using `print("A") if condition else print("B")`
  • What will the following code print? `print("A") if a > b else print("B")` when a = 2 and b = 330?

    B
  • How can you have multiple else statements on the same line in Python?
    Using chained ternary operators
  • What will the following code print? `print("A") if a > b else print("=") if a == b else print("B")` when a = 330 and b = 330?
    =
  • What does the `and` keyword do in Python?
    Combines conditional statements
  • What will the following code print? `if a > b and c > a:` when a = 200, b = 33, and c = 500?
    Both conditions are True
  • What does the `or` keyword do in Python?
    Checks if at least one condition is true
  • What will the following code print? `if a > b or a > c:` when a = 200, b = 33, and c = 500?
    At least one of the conditions is True
  • What does the `not` keyword do in Python?
    Reverses the result of a condition
  • What will the following code print? `if not a > b:` when a = 33 and b = 200?
    a is NOT greater than b
  • What are nested if statements?
    If statements inside other if statements
  • What will the following code print? `if x > 10: print("Above ten,") if x > 20: print("and also above 20!") else: print("but not above 20.")` when x = 41?
    Above ten, and also above 20!
  • What is the purpose of the pass statement in Python?
    To avoid errors in empty if statements
  • What will the following code print? `if b > a: pass` when a = 33 and b = 200?
    No output due to pass statement
  • What will the following code print? `if x > y: print("Welcome") else: print("Welcome")` when x = 5 and y = 8?
    Welcome
  • What will the following code print? `if a > b: print("Hello World")` when a = 50 and b = 10?
    Hello World
  • What will the following code print? `if a == b: print("Yes") else: print("No")` when a = 50 and b = 10?
    No
  • What will the following code print? `if a == b: print("1") elif a > b: print("2") else: print("3")` when a = 50 and b = 10?
    2
  • What will the following code print? `if a == b and c == d: print("Hello")` when a = 50, b = 10, c = 50, and d = 10?
    Hello
  • What will the following code print? `if a == b or c == d: print("Hello")` when a = 50, b = 10, c = 50, and d = 10?
    Hello
  • What are the main components of Python's conditional statements?
    • if statement
    • elif statement
    • else statement
    • Nested if statements
    • Logical operators (and, or, not)
  • What are the types of conditional statements in Python?
    1. Simple if
    2. if-else
    3. if-elif-else
    4. Nested if
    5. Short-hand if
    6. Short-hand if-else