Using classes
One way to do this is implementing those 2 function into one class, like the following:
class Database():
def __init__(self):
self.database = []
def createDatabase(self, size):
for j in range(0, size):
# I did'nt get why you pass database here, but I leaved as it is in your code
self.database.append(randomNumberGenerator(100,self.database))
def searchDatabase(self, guess):
# here I'm taking advantage of the test redundancy to shorten the code
print('[{}, {}]'.format(guess in self.database, guess))
If you get interested to python object oriented programming, see the answer to this question right here in Stack Overflow to get a basic introduction to this subject.
More about python string format used in print here
Example of usage:
db = Database()
db.createDatabase(6)
# Suppose that the database have the following numbers: 4, 8, 15, 16, 23, 42
db.searchDatabase(1)
db.searchDatabase(42)
Output
[False, 1]
[True, 42]
Without classes
def createDatabase(size):
databse = []
for j in range(0, size):
# I did'nt get why you pass database here, but I leaved as it is in your code
database.append(randomNumberGenerator(100,self.database))
return database
def searchDatabase(database, guess):
# here I'm taking advantage of the test redundancy to shorten the code
print('[{}, {}]'.format(guess in database, guess))
Example of usage equivalent to the "classy" one:
db = createDatabase(6)
# Suppose that the database have the following numbers: 4, 8, 15, 16, 23, 42
searchDatabase(db, 1)
searchDatabase(db, 42)
Gives same output as above