🔗Link: https://awsrestart.instructure.com/courses/1632/modules/items/886825
📁Repo: https://github.com/francopig/aws-python/tree/main/07. Trabajo con condicionales
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:
if
statementelse
statementelif
statementIn this exercise, you will edit a Python script to ship packages.
From the navigation pane of the IDE, choose the .py file that you created in the previous Creating your Python exercise file section.
Use the input()
function to get information from the user:
userReply = input("Do you need to ship a package? (Enter yes or no) ")
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.
Save and run the file.
At the prompt, enter yes
and press ENTER.
Confirm that you see a response.
Run the file again.
At the prompt, enter no
and press ENTER. Confirm that the program exits and nothing id displayed.