Chapter 12: Final Mission: Planet Colonization (Project)
Welcome back, Space Explorer! As we come to the end of our journey through the cosmos of Python, it’s time to take everything we’ve learned and apply it to a final project.
For our grand finale, we’ll use all the concepts we’ve learned to plan a colonization mission to a new planet. We’ll define the specifications of the spacecraft, plot the course, handle potential alien encounters, navigate through space, catalog stars and alien species, automate the daily tasks in the colony, and analyze data from the planet.
Planning the Project
Our project will be broken down into several parts, each corresponding to the concepts from a different chapter of this book:
Designing Your Spacecraft: We’ll define several variables to hold the details of our spacecraft.
Packing for Your Journey: We’ll create a list of necessary space travel items.
Space Communications: We’ll create a function that takes user input and provides an output.
Calculating Trajectories: We’ll create a program that calculates the best trajectory using given variables.
Alien Response System: We’ll build a program that simulates different responses to potential alien encounters.
Space Navigation System: We’ll build a navigation system that loops through a set of directions.
Star Catalog: We’ll create a program that organizes and manipulates star names and their attributes.
Alien Species Log: We’ll make a dictionary to store data about different alien species.
Daily Routine Automation: We’ll define functions for typical daily tasks in a space colony.
Planet Analysis: We’ll use libraries to analyze data from the new planet.
Let’s start coding!
1 # Designing Your Spacecraft
2 craft_name = "Pioneer"
3 craft_speed = 100000 # in km/h
4 craft_capacity = 1000 # in kg
5
6 # Packing for Your Journey
7 journey_items = ["food", "water", "oxygen", "fuel", "tools", "medicines", "seeds for\
8 farming", "construction materials"]
9
10 # Space Communications
11 def communicate(message):
12 print(f"Mission Control: {message}")
13
14 # Calculating Trajectories
15 def calculate_trajectory(distance, speed):
16 time = distance / speed
17 return time
18
19 # Alien Response System
20 def respond_to_alien(alien_type):
21 responses = {
22 "friendly": "Let's establish peaceful contact.",
23 "neutral": "Proceed with caution.",
24 "hostile": "Retreat and avoid contact."
25 }
26 return responses.get(alien_type, "Unknown alien type, proceed with extreme cauti\
27 on.")
28
29 # Space Navigation System
30 directions = ["forward", "left", "right", "up", "down"]
31 for direction in directions:
32 print(f"Moving {direction}")
33
34 # Star Catalog
35 stars = ["Alpha Centauri", "Beta Centauri", "Proxima Centauri", "Sirius", "Vega"]
36 star_brightness = [0.01, 0.1, 0.001, 1, 0.03]
37 for star, brightness in zip(stars, star_brightness):
38 print(f"{star} has brightness {brightness}")
39
40 # Alien Species Log
41 alien_species = {
42 "species_1": {"type": "friendly", "planet": "Mars"},
43 "species_2": {"type": "neutral", "planet": "Venus"},
44 "species_3": {"type": "hostile", "planet": "Jupiter"}
45 }
46
47 # Daily Routine Automation
48 def wake_up():
49 print("Wake up, Space Explorer!")
50 def eat_meal(meal):
51 print(f"Eating {meal}")
52 def do_science():
53 print("Doing science!")
54 def go_to_bed():
55 print("Going to bed. Good night!")
56
57 # Planet Analysis
58 import numpy as np
59 planet_data = np.array([1, 2, 3, 4, 5]) # dummy data
60 print(f"Average data value: {np.mean(planet_data)}")
Congratulations, Space Explorer! You’ve successfully planned a mission to colonize a new planet, applying all the Python concepts you’ve learned throughout this journey. You’ve navigated through variables, loops, conditionals, functions, data structures, and libraries, and you’ve emerged as a true Python space explorer.