10. Logical expressions

Let’s see an example:

1print(not False or False and True)
2print(False or True and True)
3print(not False and True or False)
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 10.1 (cl_l05_10a_en)

10.1. Example

  • The conditions for granting a motorcycle purchase loan are: having a salary greater than $1,000.00 and being over 18 years old. Check if José can get the loan:

1salary = 500.0
2age = 20
3print(salary > 1000 and age > 18)
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 10.1.1 (cl_l05_10b_en)

10.2. Example

  • Check if a student passed given that they obtained an average score of 5.8 in the exercise program and obtained an average score of 7 in the tests:

1ep = 5.8
2p = 7
3passed = ep >= 6 and p >= 6
4print(passed)
line that just executed

next line to execute

Print output (drag lower right corner to resize)
Frames
Objects

Activity: CodeLens 10.2.1 (cl_l05_10c_en)

You have attempted 1 of 2 activities on this page