You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
1.9 KiB
Python

import time
with open('corpus/words') as f:
lines = f.readlines()
print(lines)
class letterLeaf:
def __init__(self,letter,wordFruit):
self.leftAlphabet = None
self.rightAlphabet = None
self.letter = letter
self.wordFruit = wordFruit
COUNT = [10]
def print2DUtil_flat(root, space,growth_rate):
if (root == None) :
return
space += COUNT[0]
print2DUtil_flat(root.rightAlphabet, space,growth_rate)
print()
for i in range(COUNT[0], space):
print(end = " ")
print(root.letter)
for i in range(COUNT[0], space):
print(end = " ")
print(root.wordFruit)
time.sleep(growth_rate)
print2DUtil_flat(root.leftAlphabet, space,growth_rate)
def print2D(root, growth_rate):
print("here is a tree that's laying on the ground: ")
print2DUtil_flat(root, 0, growth_rate)
def grepFirstLetter(word):
firstLetter = word[0]
return firstLetter
def insertLeaf(root,wordFruit):
letter = grepFirstLetter(wordFruit)
newleaf = letterLeaf(letter,wordFruit)
x = root
y = None
while (x != None):
y = x
if (letter < x.letter):
x = x.leftAlphabet
else:
x = x.rightAlphabet
if (y == None):
y = newleaf
elif (letter < y.letter):
y.leftAlphabet = newleaf
else:
y.rightAlphabet = newleaf
return y
import random
root = None
random_fruit = random.choice(fruit_list)
root = insertLeaf(root, random_fruit)
fruit_list.remove(random_fruit)
len_list = (len(fruit_list))
while len_list > 0:
random_fruit = random.choice(fruit_list)
insertLeaf(root,random_fruit)
fruit_list.remove(random_fruit)
len_list -= 1
def ask_input():
growth_rate = int(input("Enter growth rate value for tree in seconds: "))
return growth_rate
growth_rate = ask_input()
print2D(root, growth_rate)