jeudi 4 juin 2015

How to select a specific number of random elements from a set?

I have a set of 9 elements and I want to write a program which prompts the user for an integer n, then displays n number of elements selected randomly from my set.

This is what I tried:

import random

def main():    
    best_of = eval(input("How many maps do you want to choose? : "))

    choices = ["Arkansas", "Manchuria", "Bengal", "Baja California", "Tibet", "Indonesia", "Cascade Range", "Hudson Bay", "High Plains"]

    random_choice = random.choice(choices)

    for i in range(bes_of):    
        print(random_choice)

main()




Aucun commentaire:

Enregistrer un commentaire