🚦 Day 4: Control Flow in Python – If-Else and While Loops
Welcome back to Zero to Builder: 100 Days of AI-Assisted Coding!
Today we're diving into one of the most fundamental concepts in programming: control flow. This is how your program makes decisions (if-else) and repeats actions (while loops).
Instead of continuing directly from your "Hello World" script (which remains your personal practice), today's lesson uses a fresh, fun example called "Curds and Whey" to clearly illustrate these concepts.
🎥 Watch Today's Lesson:
🔍 What You'll Learn:
1️⃣ If-Else Statements
Use these statements to help Python make decisions:
choice = input("Do you want curds and whey? (yes/no): ").lower()
if choice == 'yes':
print("Bad move. You're stuck at the table until you finish!")
else:
print("Great choice! Have a nice day!")
2️⃣ While Loops
Use loops to repeat actions until a certain condition is met:
while True:
finished = input("Press any key and Enter when you've finished your curds and whey: ")
if finished:
print("You're done! Have a great day!")
break
3️⃣ Nested Control Flow
Combine statements clearly and logically:
choice = input("Do you want curds and whey? (yes/no): ").lower()
if choice == 'yes':
print("Bad move. You're stuck at the table!")
while True:
finished = input("Press any key and Enter when done: ")
if finished:
print("Finally! You're done!")
break
else:
print("Good choice. Enjoy your day!")
🧠 Using AI to Improve Your Code
As demonstrated in today's video, sometimes AI won't automatically choose the most explicit control flow structures (if-else, while). Always explicitly ask your AI assistant (like Cursor) to rewrite or optimize your code using these statements:
Example AI Prompts:
"Rewrite my Python code clearly using if-else and while loops.""What improvements can I make to my control flow?"
🛠 Your Homework
Keep independently improving your "Hello World" program by adding your own interactive logic using control flow.
Example challenge:
Ask the user how many times they'd like to see the message. Use loops and if-else conditions to manage the flow.
✅ Advanced Considerations
When working with AI to generate or optimize control flow, consider:
Clearly communicating business logic in your prompts.
Handling edge cases and potential errors.
Ensuring readability and maintainability.
Optimizing for performance and scalability.
Explicitly requesting AI to handle security implications and multithreading when relevant.
🗓 Tomorrow: Office Hours
Join us tomorrow for our weekly Office Hours session! Share your victories, bring your struggles, and hear from peers and special guests on their journey with AI-assisted coding. We'll go live on LinkedIn—link coming soon!
Event Link>https://www.linkedin.com/events/7318472715152039936/
Happy coding, and see you tomorrow! 🚀

