🔗Link: https://awsrestart.instructure.com/courses/1632/modules/items/886825

📁Repo: https://github.com/francopig/aws-python/tree/main/07. Trabajo con condicionales

Lab overview

A section of code that compares two pieces of information is called a conditional statement. You can use conditionals to create different paths through the program. Using comparative operators, you will write a program that makes decisions.

In this lab, you will:


Exercise 1: Working with the if statement

In this exercise, you will edit a Python script to ship packages.

  1. From the navigation pane of the IDE, choose the .py file that you created in the previous Creating your Python exercise file section.

  2. Use the input() function to get information from the user:

    userReply = input("Do you need to ship a package? (Enter yes or no) ")
    
  3. Use the if statement to print a response.

    The statements in an if statement are one tab indented from the if statement. In other programming languages, brackets are often used to indicate the start and end of a logic block, but Python uses spacing:

    if userReply == "yes":
        print("We can help you ship that package!")
    

    Note: The == symbol is a comparative operator. It means is equal to.

  4. Save and run the file.

  5. At the prompt, enter yes and press ENTER.

  6. Confirm that you see a response.

  7. Run the file again.

  8. At the prompt, enter no and press ENTER. Confirm that the program exits and nothing id displayed.

Untitled