Skip to content

Instantly share code, notes, and snippets.

@mightywombat
Last active April 19, 2018 21:06
Show Gist options
  • Save mightywombat/7cf88eacda92692b4225b248203aa80f to your computer and use it in GitHub Desktop.
Save mightywombat/7cf88eacda92692b4225b248203aa80f to your computer and use it in GitHub Desktop.
practicepython.org Ex 05
# practicepython.org Ex 05
import random as ra
def randrng():
numlist = []
rnglen = ra.randrange(10, 20)
while rnglen > 0:
numlist.append(ra.randrange(1, 100))
rnglen -= 1
return numlist
range1 = randrng()
range2 = randrng()
matchy = []
for value1 in range1:
for value2 in range2:
if value1 == value2:
matchy.append(value2)
print ( "Matching numbers are, in order: " + str(sorted(matchy)))
@mightywombat
Copy link
Author

This script generates a list of randomly generated length (between 10 and 20), populated with randomly generated numbers (1 to 100) and compares them together to extract the overlapping values between the lists. It then presents the list of matching numbers at the command line, ordered lowest to highest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment