Python: Function calling from results of another function for Chatbot
I am creating a chatbot with pymessenger and wit.at. I am taking value through one entity suppose greeting and there I am setting parameters for another function but it is not working when I am calling other function.
def get_message():
sample_responses = ["Hey Welcome May I know your Roll Number?", "Hi Welcome to May I know your Roll Number"]
return random.choice(sample_responses)
def cust(value):
if value =="111":
t1 = "Thor"
val_off = "1"
elif value =="222":
t1 = "Steve"
val_off = "2"
elif value =="333":
t1 = "Tony"
val_off = "3"
else:
t1= ""
val_off =""
def get_offer(val_off):
if val_off == "1":
offer_test = ("1. Thor"+"n"+"2. Thor: Ragnarok+"n"+"3. Avenger Series")
elif val_off == "2":
offer_test = ("1. First Avenger"+"n"+"2. Winter Soldier"+"n"+"3. Civil War")
elif val_off =="3":
offer_test = ("1. Iron Man 1"+"n"+"2. Iron Man 2"+"n"+"3. Civil War")
return offer_test
app.route('/', methods=['POST'])
def webhook():
data = request.get_json()
log(data)
if data['object'] == 'page':
for entry in data['entry']:
for messaging_event in entry['messaging']:
sender_id = messaging_event['sender']['id']
recipient_id = messaging_event['recipient']['id']
if messaging_event.get('message'):
if 'text' in messaging_event['message']:
messaging_text = messaging_event['message']['text']
else:
messaging_text = 'no text'
response = None
entity, value = wit_response(messaging_text)
if entity == 'cust_greet':
response = get_message()
elif entity == 'cust_id':
test = cust(str(value))
val_off = test[1]
offer_response = get_offer(str(val_off))
esponse = "Hey "+test[0] +"👋. "+"n"+"How Can I help you? Are you interested in"+"n"+"1.Bio"+"n"+"2. Movie list"
elif entity == 'cust_movie':
response = offer_response
bot.send_text_message(sender_id, response)
When provide roll number : eg. 111 function cust()
will be called it will tell the name as Thor and set val_off = 1
and call the function call_offer
. But when I select option "2. Movie list" I am getting error:
" response = offer_response
UnboundLocalError: local variable 'offer_response' referenced before assignment"
python python-3.x function
add a comment |
I am creating a chatbot with pymessenger and wit.at. I am taking value through one entity suppose greeting and there I am setting parameters for another function but it is not working when I am calling other function.
def get_message():
sample_responses = ["Hey Welcome May I know your Roll Number?", "Hi Welcome to May I know your Roll Number"]
return random.choice(sample_responses)
def cust(value):
if value =="111":
t1 = "Thor"
val_off = "1"
elif value =="222":
t1 = "Steve"
val_off = "2"
elif value =="333":
t1 = "Tony"
val_off = "3"
else:
t1= ""
val_off =""
def get_offer(val_off):
if val_off == "1":
offer_test = ("1. Thor"+"n"+"2. Thor: Ragnarok+"n"+"3. Avenger Series")
elif val_off == "2":
offer_test = ("1. First Avenger"+"n"+"2. Winter Soldier"+"n"+"3. Civil War")
elif val_off =="3":
offer_test = ("1. Iron Man 1"+"n"+"2. Iron Man 2"+"n"+"3. Civil War")
return offer_test
app.route('/', methods=['POST'])
def webhook():
data = request.get_json()
log(data)
if data['object'] == 'page':
for entry in data['entry']:
for messaging_event in entry['messaging']:
sender_id = messaging_event['sender']['id']
recipient_id = messaging_event['recipient']['id']
if messaging_event.get('message'):
if 'text' in messaging_event['message']:
messaging_text = messaging_event['message']['text']
else:
messaging_text = 'no text'
response = None
entity, value = wit_response(messaging_text)
if entity == 'cust_greet':
response = get_message()
elif entity == 'cust_id':
test = cust(str(value))
val_off = test[1]
offer_response = get_offer(str(val_off))
esponse = "Hey "+test[0] +"👋. "+"n"+"How Can I help you? Are you interested in"+"n"+"1.Bio"+"n"+"2. Movie list"
elif entity == 'cust_movie':
response = offer_response
bot.send_text_message(sender_id, response)
When provide roll number : eg. 111 function cust()
will be called it will tell the name as Thor and set val_off = 1
and call the function call_offer
. But when I select option "2. Movie list" I am getting error:
" response = offer_response
UnboundLocalError: local variable 'offer_response' referenced before assignment"
python python-3.x function
becauseoffer_response
is not assigned anywhere in your code
– Rahul Agarwal
Dec 31 '18 at 8:30
@RahulAgarwal: Thanks for quick response. I have already assigned it. see the snippet reference here: elif entity == 'cust_id': test = cust(str(value)) val_off = test[1] offer_response = get_offer(str(val_off))
– codekiller
Dec 31 '18 at 9:22
but you have assigned it in aelif
block and the condition you are accessing is when the code doesn't go there. It has to be assigned globally to some value and can be changed when it enters a particularif
block
– Rahul Agarwal
Dec 31 '18 at 9:31
I tried to change my code by adding this in first function but still getting same error:def cust(value): if value =="111": t1 = "Thor" val_off = "1" offer_response = get_offer(str(val_off)) elif value =="222": t1 = "Steve" val_off = "2" offer_response = get_offer(str(val_off)) elif value =="333": t1 = "Tony" val_off = "3" offer_response = get_offer(str(val_off)) else: t1= "" val_off ="" return (t1,val_off,offer_response)
I am new to python, can you tell where should I put the offer_response.
– codekiller
Dec 31 '18 at 10:33
You have to add it where theoffer_response
gets assigned to some value even it is blank. So it gets assigned as soon as the code starts!!
– Rahul Agarwal
Dec 31 '18 at 10:36
add a comment |
I am creating a chatbot with pymessenger and wit.at. I am taking value through one entity suppose greeting and there I am setting parameters for another function but it is not working when I am calling other function.
def get_message():
sample_responses = ["Hey Welcome May I know your Roll Number?", "Hi Welcome to May I know your Roll Number"]
return random.choice(sample_responses)
def cust(value):
if value =="111":
t1 = "Thor"
val_off = "1"
elif value =="222":
t1 = "Steve"
val_off = "2"
elif value =="333":
t1 = "Tony"
val_off = "3"
else:
t1= ""
val_off =""
def get_offer(val_off):
if val_off == "1":
offer_test = ("1. Thor"+"n"+"2. Thor: Ragnarok+"n"+"3. Avenger Series")
elif val_off == "2":
offer_test = ("1. First Avenger"+"n"+"2. Winter Soldier"+"n"+"3. Civil War")
elif val_off =="3":
offer_test = ("1. Iron Man 1"+"n"+"2. Iron Man 2"+"n"+"3. Civil War")
return offer_test
app.route('/', methods=['POST'])
def webhook():
data = request.get_json()
log(data)
if data['object'] == 'page':
for entry in data['entry']:
for messaging_event in entry['messaging']:
sender_id = messaging_event['sender']['id']
recipient_id = messaging_event['recipient']['id']
if messaging_event.get('message'):
if 'text' in messaging_event['message']:
messaging_text = messaging_event['message']['text']
else:
messaging_text = 'no text'
response = None
entity, value = wit_response(messaging_text)
if entity == 'cust_greet':
response = get_message()
elif entity == 'cust_id':
test = cust(str(value))
val_off = test[1]
offer_response = get_offer(str(val_off))
esponse = "Hey "+test[0] +"👋. "+"n"+"How Can I help you? Are you interested in"+"n"+"1.Bio"+"n"+"2. Movie list"
elif entity == 'cust_movie':
response = offer_response
bot.send_text_message(sender_id, response)
When provide roll number : eg. 111 function cust()
will be called it will tell the name as Thor and set val_off = 1
and call the function call_offer
. But when I select option "2. Movie list" I am getting error:
" response = offer_response
UnboundLocalError: local variable 'offer_response' referenced before assignment"
python python-3.x function
I am creating a chatbot with pymessenger and wit.at. I am taking value through one entity suppose greeting and there I am setting parameters for another function but it is not working when I am calling other function.
def get_message():
sample_responses = ["Hey Welcome May I know your Roll Number?", "Hi Welcome to May I know your Roll Number"]
return random.choice(sample_responses)
def cust(value):
if value =="111":
t1 = "Thor"
val_off = "1"
elif value =="222":
t1 = "Steve"
val_off = "2"
elif value =="333":
t1 = "Tony"
val_off = "3"
else:
t1= ""
val_off =""
def get_offer(val_off):
if val_off == "1":
offer_test = ("1. Thor"+"n"+"2. Thor: Ragnarok+"n"+"3. Avenger Series")
elif val_off == "2":
offer_test = ("1. First Avenger"+"n"+"2. Winter Soldier"+"n"+"3. Civil War")
elif val_off =="3":
offer_test = ("1. Iron Man 1"+"n"+"2. Iron Man 2"+"n"+"3. Civil War")
return offer_test
app.route('/', methods=['POST'])
def webhook():
data = request.get_json()
log(data)
if data['object'] == 'page':
for entry in data['entry']:
for messaging_event in entry['messaging']:
sender_id = messaging_event['sender']['id']
recipient_id = messaging_event['recipient']['id']
if messaging_event.get('message'):
if 'text' in messaging_event['message']:
messaging_text = messaging_event['message']['text']
else:
messaging_text = 'no text'
response = None
entity, value = wit_response(messaging_text)
if entity == 'cust_greet':
response = get_message()
elif entity == 'cust_id':
test = cust(str(value))
val_off = test[1]
offer_response = get_offer(str(val_off))
esponse = "Hey "+test[0] +"👋. "+"n"+"How Can I help you? Are you interested in"+"n"+"1.Bio"+"n"+"2. Movie list"
elif entity == 'cust_movie':
response = offer_response
bot.send_text_message(sender_id, response)
When provide roll number : eg. 111 function cust()
will be called it will tell the name as Thor and set val_off = 1
and call the function call_offer
. But when I select option "2. Movie list" I am getting error:
" response = offer_response
UnboundLocalError: local variable 'offer_response' referenced before assignment"
python python-3.x function
python python-3.x function
edited Jan 2 at 8:13
Rahul Agarwal
2,19451027
2,19451027
asked Dec 31 '18 at 8:25
codekillercodekiller
196
196
becauseoffer_response
is not assigned anywhere in your code
– Rahul Agarwal
Dec 31 '18 at 8:30
@RahulAgarwal: Thanks for quick response. I have already assigned it. see the snippet reference here: elif entity == 'cust_id': test = cust(str(value)) val_off = test[1] offer_response = get_offer(str(val_off))
– codekiller
Dec 31 '18 at 9:22
but you have assigned it in aelif
block and the condition you are accessing is when the code doesn't go there. It has to be assigned globally to some value and can be changed when it enters a particularif
block
– Rahul Agarwal
Dec 31 '18 at 9:31
I tried to change my code by adding this in first function but still getting same error:def cust(value): if value =="111": t1 = "Thor" val_off = "1" offer_response = get_offer(str(val_off)) elif value =="222": t1 = "Steve" val_off = "2" offer_response = get_offer(str(val_off)) elif value =="333": t1 = "Tony" val_off = "3" offer_response = get_offer(str(val_off)) else: t1= "" val_off ="" return (t1,val_off,offer_response)
I am new to python, can you tell where should I put the offer_response.
– codekiller
Dec 31 '18 at 10:33
You have to add it where theoffer_response
gets assigned to some value even it is blank. So it gets assigned as soon as the code starts!!
– Rahul Agarwal
Dec 31 '18 at 10:36
add a comment |
becauseoffer_response
is not assigned anywhere in your code
– Rahul Agarwal
Dec 31 '18 at 8:30
@RahulAgarwal: Thanks for quick response. I have already assigned it. see the snippet reference here: elif entity == 'cust_id': test = cust(str(value)) val_off = test[1] offer_response = get_offer(str(val_off))
– codekiller
Dec 31 '18 at 9:22
but you have assigned it in aelif
block and the condition you are accessing is when the code doesn't go there. It has to be assigned globally to some value and can be changed when it enters a particularif
block
– Rahul Agarwal
Dec 31 '18 at 9:31
I tried to change my code by adding this in first function but still getting same error:def cust(value): if value =="111": t1 = "Thor" val_off = "1" offer_response = get_offer(str(val_off)) elif value =="222": t1 = "Steve" val_off = "2" offer_response = get_offer(str(val_off)) elif value =="333": t1 = "Tony" val_off = "3" offer_response = get_offer(str(val_off)) else: t1= "" val_off ="" return (t1,val_off,offer_response)
I am new to python, can you tell where should I put the offer_response.
– codekiller
Dec 31 '18 at 10:33
You have to add it where theoffer_response
gets assigned to some value even it is blank. So it gets assigned as soon as the code starts!!
– Rahul Agarwal
Dec 31 '18 at 10:36
because
offer_response
is not assigned anywhere in your code– Rahul Agarwal
Dec 31 '18 at 8:30
because
offer_response
is not assigned anywhere in your code– Rahul Agarwal
Dec 31 '18 at 8:30
@RahulAgarwal: Thanks for quick response. I have already assigned it. see the snippet reference here: elif entity == 'cust_id': test = cust(str(value)) val_off = test[1] offer_response = get_offer(str(val_off))
– codekiller
Dec 31 '18 at 9:22
@RahulAgarwal: Thanks for quick response. I have already assigned it. see the snippet reference here: elif entity == 'cust_id': test = cust(str(value)) val_off = test[1] offer_response = get_offer(str(val_off))
– codekiller
Dec 31 '18 at 9:22
but you have assigned it in a
elif
block and the condition you are accessing is when the code doesn't go there. It has to be assigned globally to some value and can be changed when it enters a particular if
block– Rahul Agarwal
Dec 31 '18 at 9:31
but you have assigned it in a
elif
block and the condition you are accessing is when the code doesn't go there. It has to be assigned globally to some value and can be changed when it enters a particular if
block– Rahul Agarwal
Dec 31 '18 at 9:31
I tried to change my code by adding this in first function but still getting same error:
def cust(value): if value =="111": t1 = "Thor" val_off = "1" offer_response = get_offer(str(val_off)) elif value =="222": t1 = "Steve" val_off = "2" offer_response = get_offer(str(val_off)) elif value =="333": t1 = "Tony" val_off = "3" offer_response = get_offer(str(val_off)) else: t1= "" val_off ="" return (t1,val_off,offer_response)
I am new to python, can you tell where should I put the offer_response.– codekiller
Dec 31 '18 at 10:33
I tried to change my code by adding this in first function but still getting same error:
def cust(value): if value =="111": t1 = "Thor" val_off = "1" offer_response = get_offer(str(val_off)) elif value =="222": t1 = "Steve" val_off = "2" offer_response = get_offer(str(val_off)) elif value =="333": t1 = "Tony" val_off = "3" offer_response = get_offer(str(val_off)) else: t1= "" val_off ="" return (t1,val_off,offer_response)
I am new to python, can you tell where should I put the offer_response.– codekiller
Dec 31 '18 at 10:33
You have to add it where the
offer_response
gets assigned to some value even it is blank. So it gets assigned as soon as the code starts!!– Rahul Agarwal
Dec 31 '18 at 10:36
You have to add it where the
offer_response
gets assigned to some value even it is blank. So it gets assigned as soon as the code starts!!– Rahul Agarwal
Dec 31 '18 at 10:36
add a comment |
1 Answer
1
active
oldest
votes
Sample function:
def cust(value):
offer_response ="" ## if it is a string
offer_response = 0 ## if it is a number
if value =="111":
t1 = "Thor"
val_off = "1"
offer_response = get_offer(str(val_off))
Try this:
elif entity == 'cust_movie':
response = "Please let me know the type of movie by pressing only the digit"+"n"+"1.Thor Series"+"n"+"2. Avenger Series" +"n"+"3.. Iron Man Series"
elif entity in( '1' , '2' ,'3'):
response = get_offer(entity)
So, As you type "cust_movie" the bot will ask you to press the type of movie you want to see. It will store the value 1,2,3
As per user entry of 1,2 or 3 the bot will check for another elif loop and go to get_offer function and the subsequent movie list will be displayed
I tried the same but when I say option 2 movie list: `elif entity == 'cust_offer': response = offer_response it will still giving same issue.
– codekiller
Dec 31 '18 at 11:32
its says ` response = offer_response NameError: name 'offer_response' is not defined` because now code is not going in cust() function.
– codekiller
Dec 31 '18 at 11:38
Tell me what is your expected output and i will edit the code that way!!
– Rahul Agarwal
Dec 31 '18 at 11:39
Correct.. Thats y i was saying assign offer response where the code goes always.. So it always have a value
– Rahul Agarwal
Dec 31 '18 at 11:40
I will explain the example: if i say roll number is 111 then chatbot will take value =111 and run the cust() and ask me if i want bio or movie list. If i say movie list then value variable is now = movie list. So now it should call get_offer() and give me 1. Thor. 2. Thor: Ragnarok 3. Avenger series. .... Thanks for your efforts and help Rahul
– codekiller
Dec 31 '18 at 11:46
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985211%2fpython-function-calling-from-results-of-another-function-for-chatbot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sample function:
def cust(value):
offer_response ="" ## if it is a string
offer_response = 0 ## if it is a number
if value =="111":
t1 = "Thor"
val_off = "1"
offer_response = get_offer(str(val_off))
Try this:
elif entity == 'cust_movie':
response = "Please let me know the type of movie by pressing only the digit"+"n"+"1.Thor Series"+"n"+"2. Avenger Series" +"n"+"3.. Iron Man Series"
elif entity in( '1' , '2' ,'3'):
response = get_offer(entity)
So, As you type "cust_movie" the bot will ask you to press the type of movie you want to see. It will store the value 1,2,3
As per user entry of 1,2 or 3 the bot will check for another elif loop and go to get_offer function and the subsequent movie list will be displayed
I tried the same but when I say option 2 movie list: `elif entity == 'cust_offer': response = offer_response it will still giving same issue.
– codekiller
Dec 31 '18 at 11:32
its says ` response = offer_response NameError: name 'offer_response' is not defined` because now code is not going in cust() function.
– codekiller
Dec 31 '18 at 11:38
Tell me what is your expected output and i will edit the code that way!!
– Rahul Agarwal
Dec 31 '18 at 11:39
Correct.. Thats y i was saying assign offer response where the code goes always.. So it always have a value
– Rahul Agarwal
Dec 31 '18 at 11:40
I will explain the example: if i say roll number is 111 then chatbot will take value =111 and run the cust() and ask me if i want bio or movie list. If i say movie list then value variable is now = movie list. So now it should call get_offer() and give me 1. Thor. 2. Thor: Ragnarok 3. Avenger series. .... Thanks for your efforts and help Rahul
– codekiller
Dec 31 '18 at 11:46
|
show 2 more comments
Sample function:
def cust(value):
offer_response ="" ## if it is a string
offer_response = 0 ## if it is a number
if value =="111":
t1 = "Thor"
val_off = "1"
offer_response = get_offer(str(val_off))
Try this:
elif entity == 'cust_movie':
response = "Please let me know the type of movie by pressing only the digit"+"n"+"1.Thor Series"+"n"+"2. Avenger Series" +"n"+"3.. Iron Man Series"
elif entity in( '1' , '2' ,'3'):
response = get_offer(entity)
So, As you type "cust_movie" the bot will ask you to press the type of movie you want to see. It will store the value 1,2,3
As per user entry of 1,2 or 3 the bot will check for another elif loop and go to get_offer function and the subsequent movie list will be displayed
I tried the same but when I say option 2 movie list: `elif entity == 'cust_offer': response = offer_response it will still giving same issue.
– codekiller
Dec 31 '18 at 11:32
its says ` response = offer_response NameError: name 'offer_response' is not defined` because now code is not going in cust() function.
– codekiller
Dec 31 '18 at 11:38
Tell me what is your expected output and i will edit the code that way!!
– Rahul Agarwal
Dec 31 '18 at 11:39
Correct.. Thats y i was saying assign offer response where the code goes always.. So it always have a value
– Rahul Agarwal
Dec 31 '18 at 11:40
I will explain the example: if i say roll number is 111 then chatbot will take value =111 and run the cust() and ask me if i want bio or movie list. If i say movie list then value variable is now = movie list. So now it should call get_offer() and give me 1. Thor. 2. Thor: Ragnarok 3. Avenger series. .... Thanks for your efforts and help Rahul
– codekiller
Dec 31 '18 at 11:46
|
show 2 more comments
Sample function:
def cust(value):
offer_response ="" ## if it is a string
offer_response = 0 ## if it is a number
if value =="111":
t1 = "Thor"
val_off = "1"
offer_response = get_offer(str(val_off))
Try this:
elif entity == 'cust_movie':
response = "Please let me know the type of movie by pressing only the digit"+"n"+"1.Thor Series"+"n"+"2. Avenger Series" +"n"+"3.. Iron Man Series"
elif entity in( '1' , '2' ,'3'):
response = get_offer(entity)
So, As you type "cust_movie" the bot will ask you to press the type of movie you want to see. It will store the value 1,2,3
As per user entry of 1,2 or 3 the bot will check for another elif loop and go to get_offer function and the subsequent movie list will be displayed
Sample function:
def cust(value):
offer_response ="" ## if it is a string
offer_response = 0 ## if it is a number
if value =="111":
t1 = "Thor"
val_off = "1"
offer_response = get_offer(str(val_off))
Try this:
elif entity == 'cust_movie':
response = "Please let me know the type of movie by pressing only the digit"+"n"+"1.Thor Series"+"n"+"2. Avenger Series" +"n"+"3.. Iron Man Series"
elif entity in( '1' , '2' ,'3'):
response = get_offer(entity)
So, As you type "cust_movie" the bot will ask you to press the type of movie you want to see. It will store the value 1,2,3
As per user entry of 1,2 or 3 the bot will check for another elif loop and go to get_offer function and the subsequent movie list will be displayed
edited Dec 31 '18 at 14:10
answered Dec 31 '18 at 10:41
Rahul AgarwalRahul Agarwal
2,19451027
2,19451027
I tried the same but when I say option 2 movie list: `elif entity == 'cust_offer': response = offer_response it will still giving same issue.
– codekiller
Dec 31 '18 at 11:32
its says ` response = offer_response NameError: name 'offer_response' is not defined` because now code is not going in cust() function.
– codekiller
Dec 31 '18 at 11:38
Tell me what is your expected output and i will edit the code that way!!
– Rahul Agarwal
Dec 31 '18 at 11:39
Correct.. Thats y i was saying assign offer response where the code goes always.. So it always have a value
– Rahul Agarwal
Dec 31 '18 at 11:40
I will explain the example: if i say roll number is 111 then chatbot will take value =111 and run the cust() and ask me if i want bio or movie list. If i say movie list then value variable is now = movie list. So now it should call get_offer() and give me 1. Thor. 2. Thor: Ragnarok 3. Avenger series. .... Thanks for your efforts and help Rahul
– codekiller
Dec 31 '18 at 11:46
|
show 2 more comments
I tried the same but when I say option 2 movie list: `elif entity == 'cust_offer': response = offer_response it will still giving same issue.
– codekiller
Dec 31 '18 at 11:32
its says ` response = offer_response NameError: name 'offer_response' is not defined` because now code is not going in cust() function.
– codekiller
Dec 31 '18 at 11:38
Tell me what is your expected output and i will edit the code that way!!
– Rahul Agarwal
Dec 31 '18 at 11:39
Correct.. Thats y i was saying assign offer response where the code goes always.. So it always have a value
– Rahul Agarwal
Dec 31 '18 at 11:40
I will explain the example: if i say roll number is 111 then chatbot will take value =111 and run the cust() and ask me if i want bio or movie list. If i say movie list then value variable is now = movie list. So now it should call get_offer() and give me 1. Thor. 2. Thor: Ragnarok 3. Avenger series. .... Thanks for your efforts and help Rahul
– codekiller
Dec 31 '18 at 11:46
I tried the same but when I say option 2 movie list: `elif entity == 'cust_offer': response = offer_response it will still giving same issue.
– codekiller
Dec 31 '18 at 11:32
I tried the same but when I say option 2 movie list: `elif entity == 'cust_offer': response = offer_response it will still giving same issue.
– codekiller
Dec 31 '18 at 11:32
its says ` response = offer_response NameError: name 'offer_response' is not defined` because now code is not going in cust() function.
– codekiller
Dec 31 '18 at 11:38
its says ` response = offer_response NameError: name 'offer_response' is not defined` because now code is not going in cust() function.
– codekiller
Dec 31 '18 at 11:38
Tell me what is your expected output and i will edit the code that way!!
– Rahul Agarwal
Dec 31 '18 at 11:39
Tell me what is your expected output and i will edit the code that way!!
– Rahul Agarwal
Dec 31 '18 at 11:39
Correct.. Thats y i was saying assign offer response where the code goes always.. So it always have a value
– Rahul Agarwal
Dec 31 '18 at 11:40
Correct.. Thats y i was saying assign offer response where the code goes always.. So it always have a value
– Rahul Agarwal
Dec 31 '18 at 11:40
I will explain the example: if i say roll number is 111 then chatbot will take value =111 and run the cust() and ask me if i want bio or movie list. If i say movie list then value variable is now = movie list. So now it should call get_offer() and give me 1. Thor. 2. Thor: Ragnarok 3. Avenger series. .... Thanks for your efforts and help Rahul
– codekiller
Dec 31 '18 at 11:46
I will explain the example: if i say roll number is 111 then chatbot will take value =111 and run the cust() and ask me if i want bio or movie list. If i say movie list then value variable is now = movie list. So now it should call get_offer() and give me 1. Thor. 2. Thor: Ragnarok 3. Avenger series. .... Thanks for your efforts and help Rahul
– codekiller
Dec 31 '18 at 11:46
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985211%2fpython-function-calling-from-results-of-another-function-for-chatbot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
because
offer_response
is not assigned anywhere in your code– Rahul Agarwal
Dec 31 '18 at 8:30
@RahulAgarwal: Thanks for quick response. I have already assigned it. see the snippet reference here: elif entity == 'cust_id': test = cust(str(value)) val_off = test[1] offer_response = get_offer(str(val_off))
– codekiller
Dec 31 '18 at 9:22
but you have assigned it in a
elif
block and the condition you are accessing is when the code doesn't go there. It has to be assigned globally to some value and can be changed when it enters a particularif
block– Rahul Agarwal
Dec 31 '18 at 9:31
I tried to change my code by adding this in first function but still getting same error:
def cust(value): if value =="111": t1 = "Thor" val_off = "1" offer_response = get_offer(str(val_off)) elif value =="222": t1 = "Steve" val_off = "2" offer_response = get_offer(str(val_off)) elif value =="333": t1 = "Tony" val_off = "3" offer_response = get_offer(str(val_off)) else: t1= "" val_off ="" return (t1,val_off,offer_response)
I am new to python, can you tell where should I put the offer_response.– codekiller
Dec 31 '18 at 10:33
You have to add it where the
offer_response
gets assigned to some value even it is blank. So it gets assigned as soon as the code starts!!– Rahul Agarwal
Dec 31 '18 at 10:36