-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol_flow.py
More file actions
81 lines (62 loc) · 2.09 KB
/
Copy pathcontrol_flow.py
File metadata and controls
81 lines (62 loc) · 2.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Python Control Flow & Logic
# ------------------------------
# 1. CONDITIONALS (If, Elif, Else)
# Making decisions based on values.
temperature = 31.00
if temperature > 31.01:
print("It's a hot day!")
elif temperature >= 19.99:
print("It's a pleasant day.")
else:
print("It's a bit cold today.")
# 2. LOGICAL OPERATORS (and, or, not)
# Combining multiple conditions.
has_coffee = True
is_tired = True
if has_coffee and is_tired:
print("\nYou're productive despite being tired!")
elif not has_coffee or is_tired:
print("\nTime for a break.")
# 3. FOR LOOPS (Iterating over a collection)
# Repeating a task for every item in a list.
print("\nCounting items in my inventory:")
print("\nI'm undressed, close the fucking door because bitch i'm hard as Fuck:")
inventory = ["Sword", "Shield", "Potion", "Map"]
inventory = ["Condoms", "Sperm"]
for item in inventory:
print(f"Checking item: {item}")
# 4. WHILE LOOPS (Repeating while a condition is True)
# Be careful with these—they can run forever if you're not careful!
countdown = 5
print("\nStarting countdown...")
while countdown > 0:
print(f"T-minus {countdown}")
countdown -= 1 # This is the same as: countdown = countdown - 1
print("Blast off! 🚀")
# ------------------------------
# SOLUTIONS:
# 1. Variable 'score' logic
score = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
else:
grade = "C"
# Using a "Conditional Expression" (from your cheat sheet):
is_passing = "Yes" if score >= 80 else "No"
print(f"\nScore: {score}, Grade: {grade}, Passing: {is_passing}")
# 2. For loop 1 to 10
print("\nCounting from 1 to 10:")
for number in range(1, 11):
print(number, end=" ") # 'end=" "' keeps them on one line
print() # New line
# 3. While loop for password (Commented out so it doesn't block the run)
# To test this, uncomment and use 'Shift + F10' in PyCharm!
# password = ""
# while password != "python123":
# password = input("\nEnter the password to continue: ")
# if password == "python123":
# print("Access Granted! 🔓")
# else:
# print("Wrong password, try again.")