Missing 1 required positional argument (Alienbot project)

Hi there, I’m getting this error when running the Alienbot program:

make_exit() missing 1 required positional argument: ‘reply’

I’ve tried looking for this error on StackOverflow and mostly have found answers relatings to class instances. But I’m not using classes. Here is my code:

def greet():
name = input("What is your name? ")
will_help = input("Hi {}, I’m Etcetera. I’m not from this planet. Will you help me learn about your planet? ".format(name))
for item in will_help:
if item in negative_responses:
print(“Goodbye”)
else:
return True

greet()

def make_exit(reply):
reply = list(exit_commands)
for reply in make_exit:
if reply in exit_commands:
print(“Goodbye”)
return True

make_exit()

Thank you!

Hello, @net9085133669. Welcome to the forum!
First, when you want to paste your code into a post, please use the </> button located in the menu bar. If you click it first, you can then paste your code into the space indicated. This will preserve formatting, including indentation, which will make your code far easier to read. It also allows others to run your code in their own environment to test it out without having to guess at how you have indented, etc.

Second, your function make_exit() takes a parameter:

When you call the function here:

You don’t include an argument for that parameter. That is the cause of your error.
I’m not sure about the body of the make_exit function. It looks like it may cause a problem after you fix the error, but it also appears you may not have posted the entire code. Anyhow, I hope this helps, and if you need further assistance please ask, and include your code using the </> button.

4 Likes

Yes, I did try that already, and when I do, it gives me a NameError: name reply is not defined.

And that is the entirety of the code I’ve written so far. The rest is a series of lists with various questions and answers. Here it is again:

def greet():
  name = input("What is your name? ")
  will_help = input("Hi {}, I'm Etcetera. I'm not from this planet. Will you help me learn about your planet? ".format(name))
  for item in will_help:
    if item in negative_responses:
      print("Peace bruh, enslave yr planet l8r")
    else:
      return True

greet()

# Define make_exit() here:

def make_exit(reply):
  for reply in make_exit:
    if reply in exit_commands:
      print("l8r g8r")
  return True

make_exit(reply)
1 Like

Thanks for formatting your code :+1:
Would you mind also posting a link to the exercise or project, so we can see what exactly is expected?

3 Likes

Sure, here it is:

Getting started with natural language processing

Thanks!

Sorry for the delay. It looks like you’re just trying to test the make_exit function. You’ll have to enter a string for the argument instead of reply. As the error states:

To test the function you could do this:

make_exit('later') #'later' is in the exit_commands tuple

If your “l8r g8r” message prints, it works!
Note: return True should be inside the if block. You should return False after the for loop finishes.

3 Likes

Ok, thanks, I tried that. This is the error I’m getting now: “in make_exit for reply in make_exit: TypeError: ‘function’ object is not iterable”

and that is using this code:

def make_exit(reply):
  for reply in make_exit:
    if reply in exit_commands:
      print("l8r g8r")
      return True
    else:
      return False

make_exit('reply')

In your for loop, you want to iterate over the exit_commands tuple, and then in your if statement, check whether the value from the exit_commands tuple is in reply.

If you’re still stuck, the make_exit() function should look similar to this:

Spoiler
def make_exit(reply):
  for command in exit_commands:
    if command in reply:
      print("l8r g8r")
      return True #if you use an else to return False, only the first word of the reply will be checked
  return False

make_exit('I will see you later.') #try this for a test
1 Like

Thanks! These details helped me understand how things actually work and helped me (mostly) fix the for loop above it:

def greet():
  name = input("What is your name? ")
  will_help = input("Hi {}, I'm Etcetera. I'm not from this planet. Will you help me learn about your planet? ".format(name))
  for resp in negative_responses:
    if resp in will_help:
      print("Peace bruh, enslave yr planet l8r")
      return 
    return True

But no matter what I put in the nested return statement (I’ve tried True, False, greet(), (), and prob a few others lol), it will print the appropriate statement when it receives a negative response, but will then ask a question anyway. The instructions for this part look like this:

4. Next we want to see if the user even wants to chat. Create a conditional that checks if the will_help response is in negative_responses . If it is, then we need an exit:

*** print a goodbye statement to the terminal (we suggest “Ok, have a nice Earth day!”)**
*** return from the function**

5. If the user didn’t respond in the negative, we know the user is probably interested in chatting. Outside the if statement, return True from the function.

I am guessing it’s asking for two Returns here and not sure why it prints the right statement but will not exit. Thanks in advance again! Someday I’m going to see this actually work

I think if you’ll make the changes I’ve suggested in my comments above, it should work as expected. If not, it seems you may have started your alienbot() function, so post your entire code, and we’ll go from there.

1 Like

Ok, thanks for the suggestion, I think it must be running my alienbot function that’s still being written, so here is all that together:

def greet():
  name = input("What is your name? ")
  will_help = input("Hi {}, I'm Etcetera. I'm not from this planet. Will you help me learn about your planet? ".format(name))
  for resp in negative_responses:
    if resp in will_help:
      print("Peace bruh, enslave yr planet l8r")
      return False
    return True
    

greet()

# Define make_exit() here:

def make_exit(reply):
  for command in exit_commands:
    if command in reply:
      print("l8r g8r")
    return True
    return False

make_exit('I will see you later')

# Define alienbot() next:
def alienbot(reply):
  reply = input(random.choice(random_questions)).lower()
  if greet is True:
    return reply
  

alienbot('ask me a question')
# Define converse() below:


# dictionary used to switch pronouns 
# and verbs in responses
reflections = {
    "i'm": "you are",
    "you're": "i'm",
    "was": "were",
    "i": "you",
    "are": "am",
    "am": "are",
    "i'd": "you would",
    "i've": "you have",
    "i'll": "you will",
    "my": "your",
    "you've": "I have",
    "you'll": "I will",
    "your": "my",
    "yours": "mine",
    "you": "I",
    "me": "you"
}
def reflect(response):
  words = response.split()
  for index, word in enumerate(words):
    if word in reflections:
      words[index] = reflections[word]
  return ' '.join(words)

And these are the instructions for creating alienbot:

Time for the main event: your alienbot() function!

Define alienbot() . Inside, add a conditional to check if calling greet() returns True .

  1. If calling greet() returns True , the user wants to chat and the alien can ask a random question from random_questions . In this case, assign reply the user input when asked a random question.

  2. It’s easier to parse text without capital letters, so change the response to lowercase.

Do you intend for your functions to return multiple times?

If so you’ve misunderstood what effect a return statement has.

This is not a loop.

  for resp in negative_responses:
    if resp in will_help:
      print("Peace bruh, enslave yr planet l8r")
      return False
    return True

Returning is something a function should be doing when the final result of the function is known.

So can you explain what the issue is here? Returning false first?

first? no. you can’t do it first or second. you can only do it once. after you’ve said “this is the final result, I’m done” you can’t keep doing things.

Do all the things that your function needs to do. Then return. It is the last thing a function does. Stopping is the last thing that can ever be done, because after stopping one is no longer doing anything.

If you have multiple results, then you might put that in a list, and then return the list when finished. It’s not some kind of limitation, if you didn’t mean to stop then return wasn’t what you’re looking for.

Or, if there’s only one result and you mean to return multiple times, then which one was the result, that doesn’t quite add up does it?

In your case, you’re doing some kind of search, and you may find something that tells you that there’s no need to continue looking, and if you do, then you’re done. This would be a good time to return.
If a result does not tell you that the search is done, then you would continue searching. This would be a bad time to stop the function.
After having searched all the whatever is searched, then, again, you’d be done. This would be a good time to return.

1 Like

If you’ll outdent the 2nd return statement in each function, you’ll be meeting this requirment:

1 Like

Thank you for the explanation…it makes a lot more sense to think about it this way.

I’m having a similar problem as I get this error:

Traceback (most recent call last):
   File "script.py", line 68, in <module>
      my_bot.greet()
   File "script.py", line 32, in greet
      if item in negative_responses:
NameError: name 'negative_responses' is not defined

This is my current code:

# importing regex and random libraries
import re
import random

class AlienBot:
  # potential negative responses
  negative_responses = ("no", "nope", "nah", "naw", "not a chance", "sorry")
  # keywords for exiting the conversation
  exit_commands = ("quit", "pause", "exit", "goodbye", "bye", "later")
  # random starter questions
  random_questions = (
        "Why are you here? ",
        "Are there many humans like you? ",
        "What do you consume for sustenance? ",
        "Is there intelligent life on this planet? ",
        "Does Earth have a leader? ",
        "What planets have you visited? ",
        "What technology do you have on this planet? "
    )

  def __init__(self):
    self.alienbabble = {'describe_planet_intent': r'',
                        'answer_why_intent': r'',
                        'cubed_intent': r''
                            }

  # Define .greet() below:
  def greet(self):
    name = input("What is your name? ")
    will_help = input("Hi {}, I'm Etcetera. I'm not from this planet. Will you help me learn about your planet? ".format(name))
    for item in will_help:
      if item in negative_responses:
        print("Ok, have a nice Earth day!")
        return False
      else:
        return True

  # Define .make_exit() here:
  def make_exit(self, reply):
    pass

  # Define .chat() next:
  def chat(self):
    pass

  # Define .match_reply() below:
  def match_reply(self, reply):
    pass

  # Define .describe_planet_intent():
  def describe_planet_intent(self):
    return "Inside .describe_planet_intent()"

  # Define .answer_why_intent():
  def answer_why_intent(self):
    return "Inside .answer_why_intent()"
       
  # Define .cubed_intent():
  def cubed_intent(self, number):
    return "Inside .cubed_intent()"

  # Define .no_match_intent():
  def no_match_intent(self):
    return "Inside .no_match_intent()"

# Create an instance of AlienBot below:
my_bot = AlienBot()
my_bot.greet()