mercredi 28 mars 2018

Generate 100 random numbers such that only 25 out of 100 numbers will be greater than 0.(remaining will be 0)

This is the code to print 100 random numbers in a 2-d grid.

[[random.randint(1,25) for i in range(10)] for j in range(10)]

How do I print the random numbers such that out of 100 randomly printed numbers, only 25 will be of value greater than 0 ? Remaining all 75 numbers should be 0, in random positions of the grid.




Aucun commentaire:

Enregistrer un commentaire