I was learning about evolution in school, and I decided to use Python to make an evolution sim. It's still in the early stages, but I finally got a version out. Here is the code
import random extinct = False print "Welcome to Evonomics Alpha! This simulation focuses on following the evolution of a species through a certain amount of years in a given environment" norp = raw_input("Do you want to make a new species or use a preexisting one? Input the whole word with a capital at the start.") if norp == "Preexisting": choice = raw_input("Which species do you want to use? Type 'giraffe', 'lion', 'elephant', 'tiger', 'wolf', or 'dog'.") name = choice if choice == "giraffe": heightdom = "Tall" heighthigh = 180 heightlow = 156 speed = 5 fight = 4 food = "Herbivore" repnumb = 3 reptime = 8 survive = 7 temp = 5 al = 30 elif choice == "elephant": heightdom = "Tall" heighthigh = 120 heightlow = 108 speed = 7 fight = 6 food = "Herbivore" repnumb = 2 reptime = 12 survive = 8 temp = 10 al = 45 elif choice == "lion": heightdom = "Tall" heighthigh = 55 heightlow = 4 speed = 35 fight = 7 food = "Omnivore" repnumb = 4 reptime = 8 survive = 5 temp = 15 al = 35 elif choice == "tiger": heightdom = "Short" heighthigh = 45 heightlow = 35 speed = 50 fight = 6 food = "Omnivore" repnumb = 3 reptime = 7 survive = 6 temp = 10 al = 25 elif choice == "wolf": heightdom = "Tall" heighthigh = 50 heightlow = 40 speed = 30 fight = 6 food = "Carnivore" repnumb = 4 reptime = 12 survive = 8 temp = 20 al = 15 elif choice == "dog": heightdom = "Tall" heighthigh = 40 heightlow = 25 fight = 4 food = "Omnivore" speed = 20 repnumb = 7 reptime = 10 survive = 7 temp = 15 al = 10 elif norp == "New": name = raw_input("What is the race called?") heightdom = raw_input("Are they more likely to be tall or short? Input the whole word with a capital at the start.") heightlow = input("What is the minimum height in inches?") heighthigh = input("What is the maximum height in inches?") food = raw_input("Is the animal a carnivore, herbivore, or an omnivore? Type the whole word with a capital at the start.") reptime = input("How many months does it take them to reproduce?") repnumb = input("How many offspring do they have at a time?") temp = input("How many degrees of natural insulation do they have?") fight = input("On a scale of 1 to 10, how well do they fight?") speed = input("On a scale of 1 to 10, how fast are they?") survive = input("On a scale of 1 to 10, how well do they adapt?") al = input("How many years is their average lifespan?") if heightlow > heighthigh: x = heightlow heightlow = heighthigh heighthigh = x average = 0.5*(heighthigh+heightlow) a=int(heightlow) b=int(heighthigh) c=int(average) if heightdom == "Tall": if random.randint(0, 4) == 4: height = random.randint(a, c) else: height = random.randint(c, b) elif heightdom == "Short": if random.randint(0, 4) == 4: height = random.randint(c, b) else: height = random.randint(a, c) x = random.randint(85, 130)/100 weight = x*height needs = 0.010203020301*weight environment = raw_input("What environment should it be released in? Type 'desert', 'tundra', 'plains', or 'forest'.") if environment == "desert": temp2 = 9 foodh = 2 foodc = 3 dis = 4 bonus = 1000000 elif environment == "tundra": temp2 = 10 foodh = 1 foodc = 2 dis = 2 bonus = 1000000 elif environment == "plains": temp2 = 65 foodh = 6 foodc = 6 dis = 5 bonus = 85 elif environment == "forest": temp2 = 50 foodh = 9 foodc = 7 dis = 7 bonus = 110 years = input("How many years should this be simulated?") pop = input("How many should be released into the wild?") monthsmore = reptime yearsdone = 0 yearsleft = al for i in range (0, years): yearsleft -= 1 popbefore = pop for j in range (0, 12): for k in range (0, pop): if temp2 + temp > 100 or temp2 + temp < 15: if not survive + random.randint(1, 2) > 10: pop -= 1 if food == "Herbivore" and needs*pop > 25*foodh: pop -= random.randint(1, pop/10) needs -= random.randint(15, 35)/10 else: if food == "Carnivore" and needs*pop > 25*foodc: pop -= random.randint(1, pop/10) needs -= random.randint(15, 35)/10 else: if food == "Omnivore" and needs*pop > 25*(foodc+foodh): pop -= random.randint(1, pop/10) needs -= random.randint(15, 35)/10 if random.randint(0, 100) < dis+1: pop = random.randint(0, 1)+pop/10 for l in range (0, pop): if food == "Carnivore": if fight > random.randint(3, 6): foodc +=0.05 elif food == "Herbivore": if fight < random.randint(5, 8) and speed < random.randint(4, 9): pop -= 1 fight += 0.1 elif food == "Omnivore": if fight > random.randint(3, 6): foodc +=0.05 if fight < random.randint(5, 8): pop -= 1 fight += 0/1 monthsmore -= 1 if monthsmore == 0: for i in range (0, pop/2): pop += repnumb x = random.randint(3, 9) x -= 6 x = x//1000 height += x y = random.randint(2, 6) y -= 4 y = y/1000 weight += y if random.randint(0, 200) == 1: if food == "Carnivore": foodc += 0.02 elif food == "Herbivore": foodh += 0.02 monthsmore = reptime if height > bonus and food == "Herbivore": foodh += 5 if weight > 75*survive: pop -= 5 weight -= 10 if weight < 20*survive: pop -= 5 weight += 10 if pop < 50: pop -= random.randint(0, 25) elif pop < 150: pop -= random.randint(0, 50) else: pop -= random.randint(1, pop/10) if yearsleft == 0: scaler = random.randint(95, 105) scaler = scaler/100 pop -= oldpop*scaler if pop < 1: print "Your species went extinct. They had average height ", height, "inches, weight ", weight, "pounds, and survived for ", yearsdone, " years. Please close the IDLE and play again!" extinct = True else: yearsdone += 1 print yearsdone, " years have passed so far. This breed of ", name, " currently has a population of ", pop, " in the ", environment, "environment." if extinct: break if extinct: break if not extinct: print "Your species went extinct. They had average height ", height, " inches, and weight ", weight, " pounds. Please close the IDLE and play again!"
That is the code. It's about 260 lines. To use it, just put it into a Python 2.7 document and run it.
Enjoy!
Last edited by Programmer_112 (2013-02-16 17:42:18)
Offline
Offline
Yeah. I'm unhappy with mine because I was too lazy to make individual beings (too much lag to test) so it killed humans off in about 2 months. I think there is not enough credit given to adapting. I'm gonna try to fix it soon. Thanks for looking!
Last edited by Programmer_112 (2013-02-16 20:40:54)
Offline
Offline
ImagineIt wrote:
Supposedly a quotation mark is invalid syntax?
Are you running it in Python 2.7? If you are, please post the error message.
Offline
Programmer_112 wrote:
ImagineIt wrote:
Supposedly a quotation mark is invalid syntax?
Are you running it in Python 2.7? If you are, please post the error message.
3.3
Offline
ImagineIt wrote:
Programmer_112 wrote:
ImagineIt wrote:
Supposedly a quotation mark is invalid syntax?
Are you running it in Python 2.7? If you are, please post the error message.
3.3
That might be the problem. What does the error message say?
Offline
we aren't even allowed to learn about evolution in school apparently.
sounds cool, I'll try it some time
Offline
zubblewu wrote:
we aren't even allowed to learn about evolution in school apparently.
sounds cool, I'll try it some time
That's sad. It's a really cool subject.
Offline
well I mean I already know about it but
hooray ultra relijus state
Offline
zubblewu wrote:
well I mean I already know about it but
hooray ultra relijus state
Which one? I live in Utah, but we still learn about evolution.
Offline
Programmer_112 wrote:
ImagineIt wrote:
Programmer_112 wrote:
Are you running it in Python 2.7? If you are, please post the error message.3.3
That might be the problem. What does the error message say?
invalid syntax.
Offline
zubblewu wrote:
we aren't even allowed to learn about evolution in school apparently.
sounds cool, I'll try it some time
-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?
Last edited by ImagineIt (2013-02-16 21:35:46)
Offline
ImagineIt wrote:
Programmer_112 wrote:
ImagineIt wrote:
3.3That might be the problem. What does the error message say?
invalid syntax.
What is the code around it? Sometimes it just gives you a approximate position
Offline
ImagineIt wrote:
zubblewu wrote:
we aren't even allowed to learn about evolution in school apparently.
sounds cool, I'll try it some time-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?
well I mean it may not be true. I heard it from my social studies teacher (who happens to be a communist and pastafarian) when we were talking about social darwinism so... but I wouldn't have a hard time believing it
anyway, is python 2.7 still available for download
Offline
zubblewu wrote:
we aren't even allowed to learn about evolution in school apparently.
sounds cool, I'll try it some time
I'm in Kentucky and we learn it
Offline
zubblewu wrote:
ImagineIt wrote:
zubblewu wrote:
we aren't even allowed to learn about evolution in school apparently.
sounds cool, I'll try it some time-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?
well I mean it may not be true. I heard it from my social studies teacher (who happens to be a communist and pastafarian) when we were talking about social darwinism so... but I wouldn't have a hard time believing it
anyway, is python 2.7 still available for download
Well there's a chance that everything may not be true. It may just be as religious people say "God's doing." Not to say I don't believe in God.
Offline
soupoftomato wrote:
zubblewu wrote:
we aren't even allowed to learn about evolution in school apparently.
sounds cool, I'll try it some timeI'm in Kentucky and we learn it
wow everyone else does it
we also can't talk about cloning
Offline
ImagineIt wrote:
zubblewu wrote:
we aren't even allowed to learn about evolution in school apparently.
sounds cool, I'll try it some time-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?
Who believes that...
Offline
sonicfan12p wrote:
ImagineIt wrote:
zubblewu wrote:
we aren't even allowed to learn about evolution in school apparently.
sounds cool, I'll try it some time-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?
Who believes that...
people used to believe the earth was flat
some actually still do
Offline
zubblewu wrote:
sonicfan12p wrote:
ImagineIt wrote:
-_- You might as well not be allowed to learn about anything science then. Like, what if people believe that the sun rising is really God lifting it up and not the Earth rotating?
Who believes that...
people used to believe the earth was flat
some actually still do
True, I guess anything can be believable to those who are prone to believe it.
Anyway, I'd love to see an Evolution simulator that actually works, without drastically changing the laws of genetics.
Last edited by sonicfan12p (2013-02-16 22:27:34)
Offline
I'd like to see one that actually simulates the DNA and the organisms development and each individual nucleotide
that might take a while to happen
Offline
sonicfan12p wrote:
zubblewu wrote:
sonicfan12p wrote:
Who believes that...people used to believe the earth was flat
some actually still doTrue, I guess anything can be believable to those who are prone to believe it.
Anyway, I'd love to see an Evolution simulator that actually works, without drastically changing the laws of genetics.
I tried. I'm working on making it better, but it doesn't work yet. Do you have any ideas on how to improve the code without too much lag?
Offline
zubblewu wrote:
I'd like to see one that actually simulates the DNA and the organisms development and each individual nucleotide
that might take a while to happen
Yep. More than a while.
Offline