Created
May 12, 2017 08:55
-
-
Save odanga94/a6af021efe46889100483595c0516b57 to your computer and use it in GitHub Desktop.
PracticePython/Exercise5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
import sys | |
# Part 1 | |
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] | |
c = [] | |
def merge(): | |
for item in a: | |
if item in b and item not in c: | |
c.append(item) | |
merge() | |
print(c) | |
print("\n") | |
#Part 3 | |
c = [x for x in a if x in b] | |
print(c) | |
#Part 2 | |
a = [] | |
b = [] | |
c = [] | |
def generate(size_a, size_b): | |
for i in range(size_a): | |
item = randint(0, 100) | |
a.append(item) | |
for i in range(size_b): | |
item = randint(0, 100) | |
b.append(item) | |
generate(10, 10) | |
merge() | |
print(a) | |
print("\n") | |
print(b) | |
print("\n") | |
print(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment