-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27_law_of_gravity.py
More file actions
85 lines (72 loc) · 2.58 KB
/
27_law_of_gravity.py
File metadata and controls
85 lines (72 loc) · 2.58 KB
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
#Choose one of the 8 planets
planet_input = input("Which planet do you want to calculate for? ")
#Choose either "Close" or "Far"
distance_input = input("Do you want to calculate the Close or Far disntace? ")
if distance_input != "Close":
if distance_input != "Far":
print("You must enter either Close or Far for your distance")
exit()
#Check if the planet is Jupiter and set the necessary values
if planet_input == "Jupiter":
mass2 = 1.8986*(10**27)
if distance_input == "Close":
distance = 741*(10**9)
else:
distance = 817*(10**9)
#Check if the planet is Saturn and set the necessary values
elif planet_input == "Saturn":
mass2 = 5.6846*(10**26)
if distance_input == "Close":
distance = 1.35*(10**12)
else:
distance = 1.51*(10**12)
#Check if the planet is Neptune and set the necessary values
elif planet_input == "Neptune":
mass2 = 10.243*(10**25)
if distance_input == "Close":
distance = 4.45*(10**12)
else:
distance = 4.55*(10**12)
#Check if the planet is Uranus and set the necessary values
elif planet_input == "Uranus":
mass2 = 8.68*(10**25)
if distance_input == "Close":
distance = 2.75*(10**12)
else:
distance = 3*(10**12)
#Check if the planet is Earth and set the necessary values
elif planet_input == "Earth":
mass2 = 5.9736*(10**24)
if distance_input == "Close":
distance = 147*(10**9)
else:
distance = 152*(10**9)
#Check if the planet is Venus and set the necessary values
elif planet_input == "Venus":
mass2 = 4.8685*(10**24)
if distance_input == "Close":
distance = 107*(10**9)
else:
distance = 109*(10**9)
#Check if the planet is Mars and set the necessary values
elif planet_input == "Mars":
mass2 = 6.4185*(10**23)
if distance_input == "Close":
distance = 205*(10**9)
else:
distance = 249*(10**9)
#Check if the planet is Mercury and set the necessary values
elif planet_input == "Mercury":
mass2 = 3.3022*(10**23)
if distance == "Close":
distance = 46*(10**9)
else:
distance = 70*(10**9)
#If the planet is anything else, we should tell the user and end the program
else:
print("You have not entered a valid planet")
exit()
mass1 = 1.9891*(10**30) #The mass of the Sun
gravity = 6.673*(10**(-11)) #The gravitational constant
force = (gravity*mass1*mass2)/(distance**2) #Calculate the force
print(force) #Print the value found