Python @ DjangoSpin

PyPro #56 Generate 10 random even numbers from 0 to 100

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Generate 10 random even numbers in Python

Generate 10 random even numbers in Python

Write a Python program to generate 10 random even numbers from 0 to 100.

generate 10 random even numbers from 0 to 100

import random

# list of even numbers between 0 and 100
bucket = [number for number in range(0, 101) if number % 2 == 0]

tenEvenRandomNumbers = random.sample(bucket, 10)

print(tenEvenRandomNumbers)		# [42, 58, 48, 64, 82, 6, 54, 100, 78, 44]

See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply