Kursinnhold
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
Oppgave
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
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 4. Kapittel 5
Challenge: Automated Bus Announcements
Oppgave
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
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 4. Kapittel 5