Skip to content

Lesson 3 names #14

@epartan

Description

@epartan
  1. I am updating all instances of "Alice" to "Anja" and "Bob" to "Noor".

  2. A continuity question. The following lesson / code takes place after Exercise 2, where my_name changes.

elif Statements
Somewhat similarly to else, elif (short for “else if”) allows us to check multiple conditions in a sequence. The elif block will only be evaluated if the previous if or elif conditions were False. This allows us to check for multiple conditions without nesting multiple if statements. For example:

# Check if my_name matches 'Anja'
if my_name == 'Anja':
    # If true, print this message
    print('Hello, Anja!')
# Otherwise, check if my_name matches 'Noor'
elif my_name == 'Noor':
    # If true, print this message
    print('Hello, Noor!')
# Otherwise
else:
    # Print this message
    print("You aren't Anja or Noor!")

In the lesson, this code is interpreted as "Hello, Anja!" However, if the participants have done the exercises, they have now updated my_name to "Noor". Is it better to use a different variable in the exercise to avoid confusion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions