100 days of code: Day 5 - lists

Last modified on 2020-06-13

Source: 100-days-of-code.

Python lists are a collection of items in a particular order. Here is a short program - rockets.py - that outputs my wish to ride on a rocket …

rockets = ['saturn v', 'soyuz', 'long march', 'falcon 9']
print(f"I would like to go for a ride on a {rockets[0].title()} rocket.")
print(f"I would like to go for a ride on a {rockets[1].title()} rocket.")
print(f"I would like to go for a ride on a {rockets[2].title()} rocket.")
print(f"I would like to go for a ride on a {rockets[-1].title()} rocket.")
rockets.append('starship')
print("However I am _especially_ looking forward to a ride on the "
            + f"upcoming {rockets[-1].title()} rocket.")
print("\n(O<")
print("(/)_")

… output …

$ python3 rockets.py
I would like to go for a ride on a Saturn V rocket.
I would like to go for a ride on a Soyuz rocket.
I would like to go for a ride on a Long March rocket.
I would like to go for a ride on a Falcon 9 rocket.
However I am _especially_ looking forward to a ride on the upcoming Starship rocket.

(O<
(/)_

Happy hacking!