Kursinnehåll
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
Uppgift
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}"
.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 4. Kapitel 5
Challenge: Automated Bus Announcements
Uppgift
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}"
.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 4. Kapitel 5