omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    TreeMaker

    Pythonista
    2
    6
    3895
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • reefboy1
      reefboy1 last edited by

      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('•-|')
      
      
      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        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
        
        1 Reply Last reply Reply Quote 0
        • reefboy1
          reefboy1 last edited by

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

          1 Reply Last reply Reply Quote 0
          • reefboy1
            reefboy1 last edited by

            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

            1 Reply Last reply Reply Quote 0
            • ccc
              ccc last edited by

              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)
              
              1 Reply Last reply Reply Quote 0
              • reefboy1
                reefboy1 last edited by

                Ooohhhh cool this works

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors