mercredi 26 avril 2017

How do I print a single RANDOM item from multiple lists? and having those items print on the same line?

my original code: simplified: (new to stackflow, so my apologies if this is the wrong way to do this)

import random

count = 0
while count < 50:
    One = ['a', 'b', 'c', 'd', 'e']
    print(random.choice(One))

    Two =['a','b']
    print(random.choice(Two))

    Three =['a','b','c','d','e','f','g','h']
    print(random.choice(Three))

    Four =['a','b']
    print(random.choice(Four))
    count = count +1

The output of my code prints each item on its own line.. if I were to run the code once(without the WHILE COUNT LOOP), the OUTPUT would read:

example:(random everytime I run the code, perfect)

c

b

h

a

multiple times: (random order, which is perfect for what i want)

d

a

f

b

__

c

b

h

a

etc...

problem: what I would like the code to do is, to take a single random item from each of the lists[one,two,three,four]... and print those random items on its own line with spacing..all while using the WHILE COUNT LOOP (to generate n number of tests)

so an example of what i want it to do would look like:

c a g b

b b f a

d a e b

assuming my lists had the correct names and associated values, would read

output:

the dog rolled over

a bird ate seeds

the cat rolled seeds

the car sat down

a snake bit me

the spider ran up

etc.etc.

(some of those dont make sense, but thats the "random" idea im working at




Aucun commentaire:

Enregistrer un commentaire