-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanet.py
123 lines (93 loc) · 3.25 KB
/
planet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# first_planet_input = input('Enter the distance from the sun for the first planet in km')
# second_planet_input = input('Enter the distance from the sun for the second planet in km')
# first_planet = int(first_planet_input)
# second_planet = int(second_planet_input)
# distance_km = second_planet - first_planet
# print(abs(distance_km))
# distance_mi = distance_km // 1.609344
# print(distance_mi)
# print(round(1.4))
# print(round(1.5))
# print(round(2.5))
# print(round(2.6))
# from math import ceil, floor
# round_up = ceil(12.5)
# print(round_up)
# round_down = floor(12.5)
# print(round_down)
########################## list##################
planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
print("The first planet is", planets[0])
print("The second planet is", planets[1])
print("The third planet is", planets[2])
number_of_planets = len(planets)
print("There are", number_of_planets, "planets in the solar system.")
planets.append("Pluto")
number_of_planets = len(planets)
print("There are actually", number_of_planets, "planets in the solar system.")
planets.pop() # Goodbye, Pluto
number_of_planets = len(planets)
print("No, there are definitely", number_of_planets, "planets in the solar system.")
#####Indexes start at zero and increase. Negative indexes start at the end of the list and work backward.
print("The last planet is", planets[-1])
print("The penultimate planet is", planets[-2])
jupiter_index = planets.index("Jupiter")
print("Jupiter is the", jupiter_index + 1, "planet from the sun")
planets_after_earth = planets[3:]
print(planets_after_earth)
amalthea_group = ["Metis", "Adrastea", "Amalthea", "Thebe"]
galilean_moons = ["Io", "Europa", "Ganymede", "Callisto"]
regular_satellite_moons = amalthea_group + galilean_moons
regular_satellite_moons.sort(reverse=True)
print("The regular satellite moons of Jupiter are", regular_satellite_moons)
user_planet = input("Please enter the name of the planet (with a capital letter to start)")
planet_index = planets.index(user_planet)
print("Here are the planets closer than " + user_planet)
print(planets[0:planet_index])
print("Here are the planets further than " + user_planet)
print(planets[planet_index + 1:])
from time import sleep
countdown = [4, 3, 2, 1, 0]
for number in countdown:
print(number)
sleep(2) # Wait 1 second
print("Blast off!! 🚀")
################# Dictionaries
planet = {
'name':'Mars',
'moons': 2
}
print(f'{planet["name"]} has {planet["moons"]} moon(s)')
planet['circumference (km)'] = {
'polar': 6752,
'equatorial': 6792
}
print(f'{planet["name"]} has a polar circumference of {planet["circumference (km)"]["polar"]}')
rainfall = {
'october': 3.5,
'november': 4.2,
'december': 2.1
}
for key in rainfall.keys():
print(f'{key}: {rainfall[key]}cm')
planet_moons = {
'mercury': 0,
'venus': 0,
'earth': 1,
'mars': 2,
'jupiter': 79,
'saturn': 82,
'uranus': 27,
'neptune': 14,
'pluto': 5,
'haumea': 2,
'makemake': 1,
'eris': 1
}
moons=planet_moons.values()
total_planets= len(planet_moons.keys())
total_moons = 0
for moon in moons:
total_moons = total_moons + moon
average = total_moons / total_planets
print(f'Each planet has an average of {average} moons')