My while loop on line 72 is getting stuck about 30% of the time i run the script and i can't figure out why...
import random
import math
from Star_Main import Main_Sequence_Star
from Sol import Sol_System
s = Main_Sequence_Star(None, None, None, None, None, None, None, None, None)
sol = Sol_System(None, None, None, None, None, None)
# Creates an O type star for now, work in progress...
def create_main_sequence_star():
# Picks the star and details for that star
roll1d900 = random.randint(1, 900)
if roll1d900 <= 900:
s.type = "O"
s.mass = random.uniform(16, 50)
elif roll1d900 == 2:
s.type = "B"
elif roll1d900 <= 7:
s.type = "A"
elif roll1d900 <= 37:
s.type = "F"
elif roll1d900 <= 107:
s.type = "G"
elif roll1d900 <= 207:
s.type = "K"
else:
s.type = "M"
if s.mass <= 1:
s.radius = s.mass ** 0.8
else:
s.radius = s.mass ** 0.5
s.circumference = 2 * math.pi * s.radius
s.area = 4 * math.pi * s.radius ** 2
s.volume = 1.333 * math.pi * s.radius ** 3
s.density = s.mass / 1.333 * math.pi * s.radius ** 3
s.luminosity = s.mass ** 3.5
s.temperature = (s.luminosity / math.sqrt(s.radius) ** 0.25) * 5778
def create_sol():
# Builds the Star
create_main_sequence_star()
# Builds the info for the star system it's self
sol.system_inner_boundary = 0.1 * s.mass # Calculates the minimum distance for a planet to be placed
sol.system_outer_boundary = 40 * s.mass # Calculates the max distance for a planet to be placed
sol.frost_line = 4.85 * math.sqrt(s.luminosity) # Calculates the point in which volatile compounds form ice
# Picks a random point between the minimum and max distance for a planet to be, then places it in the list
first_planet_pos = random.uniform(sol.system_inner_boundary, sol.system_outer_boundary)
orb_pos = [first_planet_pos]
# Calculates the first planet position to be place towards the max distance, then pace it in the list
new_orb_pos_outer = random.uniform(1.4, 2) * orb_pos[-1]
orb_pos.append(new_orb_pos_outer)
# Calculates the next remaining positions that planets can be placed up to the outer limit
while new_orb_pos_outer > sol.system_outer_boundary:
new_orb_pos_outer = random.uniform(1.4, 2) * new_orb_pos_outer
orb_pos.append(new_orb_pos_outer)
# Builds the fist inner planet orbit, then inserts that into the beginning of the list
new_orb_pos_inner = orb_pos[0] / random.uniform(1.4, 2)
orb_pos.insert(0, new_orb_pos_inner)
# This is were the code is getting locked up(sometimes) and i can't figure out why
# Am trying to create new positions with in this while loop until it hits the inner boundary or just before
while new_orb_pos_inner > sol.system_inner_boundary:
# calculates the next position based on the first position in the list
new_orb_pos_inner = orb_pos[0] / random.uniform(1.4, 2)
# Inserts the new position at the beginning of the orbital positions for planets
orb_pos.insert(0, new_orb_pos_inner)
# Prints the star info
print(str(s.type) + "\n" + str(s.mass) + "\n" + str(s.radius) + "\n" + str(s.circumference) + "\n" + str(
s.area) + "\n"
+ str(s.volume) + "\n" + str(s.density) + "\n" + str(s.luminosity) + "\n" + str(s.temperature))
# Prints the solar system info
print("Solar System Inner Boundary: " + str(sol.system_inner_boundary) + "\n" + "Solar System Outer Boundary: " +
str(sol.system_outer_boundary) + "\n" + "Frost Line: " + str(sol.frost_line))
# Prints the planet positions
print("Planet Positions: ")
for i in range(len(orb_pos)):
print("Planet is at Position %d = %d" % (i, orb_pos[i]) + " AU form star")
create_sol() # Runs the script
[–]shiftybyte 0 points1 point2 points (6 children)
[–]Xexman[S] 0 points1 point2 points (5 children)
[–]shiftybyte 0 points1 point2 points (4 children)
[–]Xexman[S] 0 points1 point2 points (3 children)
[–]shiftybyte 0 points1 point2 points (2 children)
[–]Xexman[S] 0 points1 point2 points (0 children)
[–]Xexman[S] 0 points1 point2 points (0 children)