Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8666327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:42:04+00:00 2026-06-12T17:42:04+00:00

so I need to make a program that generates generations of random equally fit

  • 0

so I need to make a program that generates generations of random equally fit alleles of a theoretical organism with a single gene.

I start with a list containing one mutated allele 2, and then I choose 3 alleles for the next generation, and append them to the list for the next generation

import random

p = [1,1,1,2]

from random import choice
n=len(p)-1

for i an range(n):
    p.append(choice(p))

problem is, this does not remove the allele that was not chosen.
how can I adapt this program so that the non-chosen allele is removed from the list?

thanks

–
edit

the out put of the program would look something like this

[1,1,1,2,1,2,1]

this would represent a population of 7 organisms with the 2 different alleles. This represents the 2nd generation as there are double alleles of the 3 chosen alleles. this simulated 2 offspring of the 3 chosen alleles.
but the alleles that was not chosen (in this case 1) should not be present in this generation.
so what I want to know is how to remove it from the list here

nb. sorry about being a bit verbose

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:42:05+00:00Added an answer on June 12, 2026 at 5:42 pm
    import random 
    n = 4 
    
    A = [i for i in xrange(n)]
    B = [1,1,1,2]
    NextGeneration = [] 
    for i in xrange(n-1):
        last = n - i - 1
        actualChoice =  random.randint(0,last)   
        NextGeneration.append(B[A[actualChoice]])  
        auxSwap = actualChoice 
        A[actualChoice] = A[last] 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make a program that generates a password that is saved in
I need to make a program that adds long integers without using the biginteger
I need to be able to make a program that looks through a mailbox
I need to make the program which have one form that contains PNG image
I need to generate a program that generates the Fibonacci Sequence Here is what
I need to make a java program with a security and a login system
I need make some action (dump statistical data) before the Dart program ends. The
Need to make certain Ruby strings in my program to be immutable. What is
So basically I'm making a program in C# and I need to make a
I am writing a program that generates standard alias names per table name. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.