-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_bool.py
More file actions
38 lines (31 loc) · 1.09 KB
/
Copy pathpython_bool.py
File metadata and controls
38 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 1. Basic booleans
is_admin = True
is_logged_in = False
print("is_admin:", is_admin, "type:", type(is_admin))
print("is_logged_in:", is_logged_in, "type:", type(is_logged_in))
# 2. Comparisons produce booleans
a = 10
b = 20
print("\n--- Comparisons ---")
print("a == b:", a == b)
print("a != b:", a != b)
print("a < b:", a < b)
print("a > b:", a > b)
print("a <= b:", a <= b)
print("a >= b:", a >= b)
# 3. Logical operators (and, or, not)
print("\n--- Logical operators ---")
print("is_admin and is_logged_in:", is_admin and is_logged_in)
print("is_admin or is_logged_in:", is_admin or is_logged_in)
print("not is_logged_in:", not is_logged_in)
# 4. Combining input, numbers and booleans
print("\n--- User input with booleans ---")
age_str = input("Enter your age: ")
age = int(age_str)
is_adult = age >= 18
print("Is adult?", is_adult)
# 5. Practice tasks:
# - Ask the user for a number and print whether it is even or odd.
# (Hint: number % 2 == 0)
# - Ask for a password and check if it equals a stored value (like "secret123").
# - Ask for two numbers and print True if the first is bigger than the second.