Conditional while loops
You've offered to help build a program that LLM Camp can use to promote an upcoming new course launching on the 26th of the month.
Today's date is the 22nd, and they have a pre-release version available from the 24th for all users who purchase a subscription on or before the 24th!
You'll need to build a custom workflow that provides tailored messages depending on the date.
Note that if your while
loop takes too long to run, or your session is expiring, you might have created an infinite loop. In particular, remember to indent the contents of the loop using four spaces or auto-indentation, and make sure the conditions are such that the loop has a stopping point.
This exercise is part of the course
Introduction to Python for Developers
Exercise instructions
- Create a
while
loop based oncurrent_date
being less than or equal torelease_date
. - Check if
current_date
is less than or equal to24
and, if so, print"Purchase before the 25th for early access"
- Otherwise, check if
current_date
is equal to25
, printing"Coming soon!"
. - After all checks, increment
current_date
by one for each day that passes.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
release_date = 26
current_date = 22
# Create a conditional loop while current_date is less than or equal to the release_date
____:
# Promote purchases
____:
print("____")
# Check if the date is equal to the 25th
____:
print("____")
else:
print("Available now!")
# Increment current_date by one
____ += ____