Course Content
Python Functions Tutorial
Python Functions Tutorial
1. What is a Function in Python?
2. Positional and Optional Arguments
4. Function Return Value Specification
Challenge: Automated Bus Announcements
Task
Swipe to start coding
If you've ever ridden a bus or tram, you know that station announcements are pre-recorded and cycle continuously. Implement a generator function bus_announcements
to simulate an automated bus announcement system.
- Use an infinite loop to cycle through the stops continuously.
- Iterate over each stop in the
stops
list. - Use
yield
to return the current stop in the format"Next stop: {stop}"
.
Solution
Everything was clear?
Thanks for your feedback!
Section 4. Chapter 5
Challenge: Automated Bus Announcements
Task
Swipe to start coding
If you've ever ridden a bus or tram, you know that station announcements are pre-recorded and cycle continuously. Implement a generator function bus_announcements
to simulate an automated bus announcement system.
- Use an infinite loop to cycle through the stops continuously.
- Iterate over each stop in the
stops
list. - Use
yield
to return the current stop in the format"Next stop: {stop}"
.
Solution
Everything was clear?
Thanks for your feedback!
Section 4. Chapter 5