Conversation
|
This is my Handin for MP2 |
| one = ['x','y'] | ||
| function = ['x','y','cos_pi','sin_pi','prod','square','average','square_root'] | ||
| if max_depth == 1: | ||
| return one[random.randint(0,1)] |
There was a problem hiding this comment.
You could also use random.choice(one), that grabs a random element from the list and is (in my opinion, at least) a slightly cleaner way to handle it. That said, it's entirely your call!
| import math | ||
|
|
||
|
|
||
| def build_random_function(min_depth, max_depth): |
There was a problem hiding this comment.
Hmm. I don't believe that the function, as you've written it, actually uses min_depth for anything - it always makes a function of max_depth. That said, it still works, and I suppose that it's technically correct.
For what it's worth, there's a handful of different ways you could handle min_ and max_depth - one option is to just randomly pick one if they're not the same, and another would be to start allowing the 'one' functions as soon as min_depth hits 1, but not force them until max_depth is 1.
| #check reversed input range | ||
| reverseInput = False | ||
| oldMin = min( input_interval_start, input_interval_end ) | ||
| # print(oldMin) |
There was a problem hiding this comment.
In general, before turning things in it's best to remove these debugging print statements.
No description provided.