0

I have a piece of code giving me an error on the following line

Reset cart is a function shown below. Can someone please tell me how I can fix this?

[pre_s, s, pre_a, a, x, x_dot, theta, theta_dot] = reset_cart(beta)    # reset the cart pole to initial state

TypeError: 'NoneType' object is not iterable

[pre_s, s, pre_a, a, x, x_dot, theta, theta_dot] = reset_cart(beta)
def reset_cart(beta):
pre_s=1
s=1
pre_a=-1  
a=-1   


x = 0
x_dot = 0
theta = 0
theta_dot = 0.01
ndmeiri
  • 4,979
  • 12
  • 37
  • 45
Stevy KUIMI
  • 47
  • 2
  • 6
  • Where is the return statement? If you are expecting the values to be returned they must explicitly be returned. Also using a list, hmm I think you need a tuple here on the return statement and you should remove the square brackets that is a syntax error. Additionally, you are calling a function before it is defined which means python, being interpreted, won't know about it. – Paula Thomas May 18 '18 at 19:49
  • put your code and errors with proper format tags – Mohammad Kanan May 18 '18 at 21:15
  • Hello Sir, thank you so much for your intake but i am completely new to coding and python, so i pretty much do not understand most of the things you asking me to do. Should I replace the brackets by something else (maybe parentheses ). – Stevy KUIMI May 19 '18 at 23:17
  • Also should the function come before the place its called? – Stevy KUIMI May 19 '18 at 23:18

1 Answers1

0

You're missing a key part of your reset_cart function: The return.

Right now, when your reset_cart function finishes, all those variables it just set disappear because they were never assigned values outside of the function. The main way to get values from a function to wherever else you want to use them is to return them with the return statement.

In this case, you're trying to set those 8 elements to the values given in the function, so return a list that holds those 8 elements:

def reset_cart(beta):

    pre_s=1
    s=1
    pre_a=-1  #the agent is taking no action
    a=-1

    x = 0
    x_dot = 0
    theta = 0
    theta_dot = 0.01
    return [pre_s, s, pre_a, a, x, x_dot, theta, theta_dot]

For more information on returning variables and on variable scopes, see:

What is the purpose of the Return statement?

Davy M
  • 1,697
  • 4
  • 20
  • 27