Python Forum
Increasing depth in python
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Increasing depth in python
#11
It applies all rules in rules. That's what I can get of information from the task description.

but I think it is Strings. Like letters

And yes, F should be replaced by a list of other letters, like F L F R F L F
Reply
#12
Sweet. So what's your code look like so far?
Reply
#13
def step(rules, state):
   for rule in rules:
       state=rule(state)
    return state
it's not correctly written here i see.... i need the tabs but they are there in my python file.
I get an error saying "Error: 'str' object is not callable."
Should i use global because that doesn't seem to work either.
Reply
#14
When posting code, use the "Python" button (6th button from right)

When posting errors, use the "Red X" button (5th button from right)
Error:
Error: 'str' object is not callable.
You should post the entire Traceback error
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#15
The error message says the string isn't callable. Which means that code I wrote for you won't work.
Globals have nothing to do with this, so using a global won't do anything to help.
And code will be formatted correctly if you insert it into a code box.

Try again :)
Reply
#16
def step(rules, state):
   for rule in rules:
      state=rule(state)
   return state
   
step("F",["F","R","L","F"])    
Error:
Traceback (most recent call last): File "C:\Users\Joach\Desktop\Gedit\Projekter-Latex\projekt1-2016\task8.py", line 11, in <module> step("F",["F","R","L","F"]) File "C:\Users\Joach\Desktop\Gedit\Projekter-Latex\projekt1-2016\task8.py", line 3, in step state=rule(state) TypeError: 'str' object is not callable

Im just a little stuck, i have no ideer of what to do at this point :(

Any help? or then i will seek further knowledge on other sites. Im desperate cause im the worst at programming... it seems so simple but yet i fail to do it right...
Reply
#17
"A little stuck"? But you haven't done anything yet. We're not going to do your homework for you. The only thing you've done so far is copy the code I gave, without any modifications whatsoever. Please, put in a little effort, or the rest of the class will be extremely difficult for you.
Reply
#18
I think i came up with something. I basicly just repeated the steps from previous task. the apply(left, right, state)

def step(rules, state):
  result=[]
  for x in state:
     if x==rules:
        result.append(state)
     else:
        result.append(x)

[inner for outer in result for inner in outer]

print(result)

#This funktion is not made yet. Dont think about it!!!
def compute(depth, rules, start):
  print()

step("F",["F","L","F","R","F","L","F"])   
Now i just need to flatten it but it didn't seem to work as planned.

Update!!!

I found out how to remove the brackets but still haven't removed 2 outer ones. any ideer?
I did this:

def step(rules, state):
   result=[]
   for x in state:
       if x==rules:
           result.append(state)
       else:
           result.append(x)
   
   flatten = [inner for outer in result for inner in outer]
   print(flatten)

#This funktion is not made yet. Dont think about it!!!
def compute(depth, rules, start):
   print()
   
step("F",["F","L","F","R","F","L","F"])
and got this

Output:
['F', 'L', 'F', 'R', 'F', 'L', 'F', 'L', 'F', 'L', 'F', 'R', 'F', 'L', 'F', 'R', 'F', 'L', 'F', 'R', 'F', 'L', 'F', 'L', 'F', 'L', 'F', 'R', 'F', 'L', 'F']
But as you see i still need to remove the last 2 at each side.
Reply
#19
That is flat.  The only way to get any flatter is if it isn't a list anymore.  If that's your goal, right before your print, you can do...
flatten = ''.join(flatten)
Reply
#20
Okay, so this is my last try.

Im almost done, i just need to make this "start" int function properly.

I made it this far:
def step(rules, state):
   result=[]
   for x in state:
      if x==rules:
         result.append(state)
      else:
         result.append(x)

   flatten = [inner for outer in result for inner in outer]
   print(flatten)

#this function description is to write a function compute(depth,rules,start) that uses the step function depth times to transform the list start into a list representing a fractal of depth depth.
   def compute(depth, rules, start):
      for i in range(depth):
         step("F",["F","L","F","R","F","L","F"])

compute(1,"F",["F","R"])
the list "start" is not in use right now, and i just need some hints to what i can do.
I think i came a lot longer on my own, so can you plz help me a bit here?

I've written what the function is supposed to do in the #symbol above the def compute() function.

best regards Malling
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  "RecursionError: maximum recursion depth exceeded in comparison" hhydration 1 1,815 Sep-26-2020, 03:07 PM
Last Post: deanhystad
  Digits increasing meknowsnothing 6 4,075 Feb-17-2019, 11:22 AM
Last Post: scidam
  Increasing difficulty of a maths game Maxxy_Gray 1 3,179 Apr-04-2018, 03:00 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020