mardi 14 août 2018

Choosing from a randomly generated list - python

I'm trying to make a random list thing in python. Every time you run the code, random words from a list would appear in order. What i did wor this to happen was this:

import random
numSelect = 0
list = ['thing1', 'thing2', 'thing3', 'thing4', 'thing5']
for i in range(random.randint(1, 3)):
    rThing = random.choice(list)
    numSelect = numSelect + 1
    print(numSelect, '-' , rThing)

The objective is that the user is asked to choice something from the list that would display. Don't know if i'm being clear and my english kinda sucks. Anyways here is an example of the output that i want

1 - thing4

2 - thing2

Which one do you choose?: 

(User would type '2')

*output of thing2*




Aucun commentaire:

Enregistrer un commentaire