Forum Archive

TreeMaker

reefboy1

Build a tree :)

#coding: utf-8
import console
print('1 space is stub 2 spaces is branch 3 spaces is apple')
for x in range(100):
    tb = raw_input(' ')
    if tb == ' ':
        console.set_color(0.50, 0.25, 0.00)
        print('  |')
    elif tb == '  ':
        console.set_color(0.50, 0.25, 0.00)
        print(' -|')
    elif tb == '   ':
        console.set_color(1.00, 0.00, 0.00)
        print('•-|')

ccc

I love it! Some enhancement ideas...

#coding: utf-8
import console, random

tree_program = ' ,  ,   ,  ,   ,  ,   ,  , , , '.split(',')
# tree_program = None  # uncomment this line to let the user build their own tree

def tree_maker(tb):
    if tb == ' ':
        console.set_color(0.50, 0.25, 0.00)
        print('  |')
    elif tb == '  ':
        console.set_color(0.50, 0.25, 0.00)
        print(random.choice([' -|', '  |-']))
    elif tb == '   ':
        console.set_color(1.00, 0.00, 0.00)
        print(random.choice(['•-|', '  |-•']))

if tree_program:
    print('Drawing a tree from: {}.'.format(tree_program))
    for x in tree_program:
        tree_maker(x)
else:
    print('1 space is stub 2 spaces is branch 3 spaces is apple')
    for x in range(100):
        tree_maker(raw_input(' '))

console.set_color(0, 0, 0)  # be kind to the next program and go back to black
reefboy1

Cool! It would be awesome to make achievements. I'm working on that now. Thanks!

reefboy1

How can I tell how many times the user has entered something? I tried making an if statement to try it but it didn't work

ccc

Let's use a dictionary to keep track of how many times the user entered each value...

watcher_dict = {}  # a new empty dict
while True:
    user_data = raw_input()
    if not user_data:  # enter no data to...
        break          # end the loop
    tree_maker(user_data)
    # record the user_data into watcher_dict
    if user_data in watcher_dict:     # if it is already in the dict
        watcher_dict[user_data] += 1  # then add 1 to it
    else:                             # if it is not yet in the dict
        watcher_dict[user_data] = 1   # then set it to 1

print('watcher_dict:', watcher_dict)
reefboy1

Ooohhhh cool this works