lundi 26 mars 2018

List.remove(x) not in list? How to remove object from array once it has been selected?

I am trying to make a program to randomly assign each day 2 topics for a project. Can anyone help identify the error in this code/ explain how i'd go about doing this.

import random


x=0 
days_ahead = 30
sting_array = [ 'Respiration', 'Microbiology', 'Population size and ecosystems', 'Human Impact on the environment', 'Sexual Reproduction in humans', 'Sexual Reproduction in plants', 'Inheritance', 'Variation and evolution',
                'Application of reproduction and genetics', 'Homeostasis', 'nervous system', 'chemical elements and biological compounds', 'cell structure and organisation', 'cell membrane and transport', 'Enzymes', 'Nucleic Acids and Their functions'
                'The cell cycle and cel division', 'Classification and biodiversity', 'Adaptations for gas exchange', 'Adapt for trans animals', 'Adapt for trans plants', 'adapts for nutrition',         ]
lele = [ 'Rates of reaction', 'Equilibrium', 'Acids and Bases', 'Buffers and neutrilisation', 'Enthalpy and Entropy', 'Redox and Electrode Potentials', 'Transition Metals',
         'Periodicity', 'Enthalpy', 'Reactivity Trends', 'Reaction rates and equilibrium', 'Alkanes', 'Alkenes', 'Alcohols', 'Haloalkanes', 'Organic Synthesis', 'Aromatic Chemistry',
         'Carbonyls and Carboxylic Acids', 'Amine, aminio acid and proteins', 'Chromatography and Spectroscopy']


while x< 30:
    x+=1
    pee_pee = random.choice(sting_array)
    wee_wee= random.choice(sting_array)
    sting_array.remove(wee_wee)
    sting_array.remove(pee_pee)
    oui_oui = pee_pee + " and " + wee_wee
    print ("day " +str(x)+ " study " + (oui_oui))

if x==30:
    print ("Render complete, terminate")

I was going to copy the same code for sting_array for the lele- to clarify so that each day would be assigned 2 topics of biology and 2 of chemistry. However before I get that far list.remove(x) error appears! ANY methods on how to randomly select string items and then remove them from the list would be very helpful thnx.

ben.




Aucun commentaire:

Enregistrer un commentaire