Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Priorities | ¿Verdadero o Falso?
Tipos de Datos en Python

book
Priorities

When it comes to programming, being able to prioritize logical statements like and and or is crucial. Earlier, you worked with math operations such as + and *. You might remember from school that * has higher precedence than +. The same rule applies to logical operators — and takes priority over or.

Let's examine an example and make a guess about the result! If you're worried about making an error, feel free to check the hints in this chapter and refer to the table. Keep in mind that you should perform the action inside the brackets first!

statement = ((True or True) and False) or True
print(statement)
12
statement = ((True or True) and False) or True print(statement)
copy

Let's break down this statement and look at each iteration to avoid any misunderstanding:

  1. ((True or True) and False) or True;

  2. (True and False) or True;

  3. False or True;

  4. True.

Tarea

Swipe to start coding

As an accountant, your goal is to ensure that all report checks return True. Replace each ___ with either True or False so that all variables equal True.

Solución

# This should be `True`: either the report is manually approved, or it passed automatic checks (which failed here)
report_is_approved = True or (True and False)

# This should be `True`: even if some conditions fail, an override can still validate the report
report_is_validated = (False and (True and True)) or True

# This should be `True`: if the report passed through fallback checks and final confirmation
report_is_final = ((False or False) or True) and True

print("Variable report_is_approved equals:", report_is_approved)
print("Variable report_is_validated equals:", report_is_validated)
print("Variable report_is_final equals:", report_is_final)
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 7
single

single

# This should be `True`: either the report is manually approved, or it passed automatic checks (which failed here)
report_is_approved = ___ or (True and False)

# This should be `True`: even if some conditions fail, an override can still validate the report
report_is_validated = (False and (True and True)) or ___

# This should be `True`: if the report passed through fallback checks and final confirmation
report_is_final = ((False or False) or True) and ___

print("Variable report_is_approved equals:", report_is_approved)
print("Variable report_is_validated equals:", report_is_validated)
print("Variable report_is_final equals:", report_is_final)

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt