Unresolved reference in defined functionCalling a function of a module by using its name (a string)How to flush output of print function?Using global variables in a functionHow to make a chain of function decorators?How do I pass a variable by reference?Peak detection in a 2D arrayReading a .txt into a definitionHow do you define __str__ in python when including newline characters?Unresolved reference issue in PyCharmPython: How to update list with two elements

Professor refuses to write a recommendation letter to students who haven't written a research paper with him

How to make a pipe-divided tuple?

Filling attribute tables with values from the same attribute table

Why are some hotels asking you to book through Booking.com instead of matching the price at the front desk?

Python reimplementation of Lost In Space by Tim Hartnell

How do draw effects during the discard phase work?

Do 643,000 Americans go bankrupt every year due to medical bills?

Why can't some airports handle heavy aircraft while others do it easily (same runway length)?

Why is it that I have to play this note on the piano as A sharp?

What's this inadvertent thing?

What does "先が気になる" mean?

How can electricity be positive when electrons are negative?

Friend is very nit picky about side comments I don't intend to be taken too seriously

Explanation of switch statement constraints on variably modified types in C standard

Examples where "thin + thin = nice and thick"

What is the "Brake to Exit" feature on the Boeing 777X?

When does order matter in probability?

Can taking my 1-week-old on a 6-7 hours journey in the car lead to medical complications?

Project Euler Problem 45

What is the extent of the commands a Cambion can issue through Fiendish Charm?

Why is Sojdlg123aljg a common password?

Is it right to use the ideas of non-winning designers in a design contest?

k times Fold with 3 changing extra variables

What's in a druid's grove?



Unresolved reference in defined function


Calling a function of a module by using its name (a string)How to flush output of print function?Using global variables in a functionHow to make a chain of function decorators?How do I pass a variable by reference?Peak detection in a 2D arrayReading a .txt into a definitionHow do you define __str__ in python when including newline characters?Unresolved reference issue in PyCharmPython: How to update list with two elements






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm trying to call a function that I defined in the code, however, it's saying that it's not defined? The error is where I have "add_to()" it's saying it's not defined. What am I doing wrong here?



grocery_list = ['salmon', 'beef', 'eggs', 'milk']

print(grocery_list)
question = input("Would you like to add anything to the list?: ")
if question == "yes" or "y" or "Y":
add_to()
else:
print("Enjoy your shopping")


def add_to():
input("Please enter the item you'd like to add: ")
grocery_list.append(str(input))


print(grocery_list)









share|improve this question


























  • Put the definition of add_to at the top.

    – Loocid
    Mar 28 at 6:00











  • Wow, I feel stupid. thank you

    – MrS
    Mar 28 at 6:07


















1















I'm trying to call a function that I defined in the code, however, it's saying that it's not defined? The error is where I have "add_to()" it's saying it's not defined. What am I doing wrong here?



grocery_list = ['salmon', 'beef', 'eggs', 'milk']

print(grocery_list)
question = input("Would you like to add anything to the list?: ")
if question == "yes" or "y" or "Y":
add_to()
else:
print("Enjoy your shopping")


def add_to():
input("Please enter the item you'd like to add: ")
grocery_list.append(str(input))


print(grocery_list)









share|improve this question


























  • Put the definition of add_to at the top.

    – Loocid
    Mar 28 at 6:00











  • Wow, I feel stupid. thank you

    – MrS
    Mar 28 at 6:07














1












1








1








I'm trying to call a function that I defined in the code, however, it's saying that it's not defined? The error is where I have "add_to()" it's saying it's not defined. What am I doing wrong here?



grocery_list = ['salmon', 'beef', 'eggs', 'milk']

print(grocery_list)
question = input("Would you like to add anything to the list?: ")
if question == "yes" or "y" or "Y":
add_to()
else:
print("Enjoy your shopping")


def add_to():
input("Please enter the item you'd like to add: ")
grocery_list.append(str(input))


print(grocery_list)









share|improve this question
















I'm trying to call a function that I defined in the code, however, it's saying that it's not defined? The error is where I have "add_to()" it's saying it's not defined. What am I doing wrong here?



grocery_list = ['salmon', 'beef', 'eggs', 'milk']

print(grocery_list)
question = input("Would you like to add anything to the list?: ")
if question == "yes" or "y" or "Y":
add_to()
else:
print("Enjoy your shopping")


def add_to():
input("Please enter the item you'd like to add: ")
grocery_list.append(str(input))


print(grocery_list)






python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 7:05









Rachit kapadia

5756 silver badges18 bronze badges




5756 silver badges18 bronze badges










asked Mar 28 at 5:58









MrSMrS

213 bronze badges




213 bronze badges















  • Put the definition of add_to at the top.

    – Loocid
    Mar 28 at 6:00











  • Wow, I feel stupid. thank you

    – MrS
    Mar 28 at 6:07


















  • Put the definition of add_to at the top.

    – Loocid
    Mar 28 at 6:00











  • Wow, I feel stupid. thank you

    – MrS
    Mar 28 at 6:07

















Put the definition of add_to at the top.

– Loocid
Mar 28 at 6:00





Put the definition of add_to at the top.

– Loocid
Mar 28 at 6:00













Wow, I feel stupid. thank you

– MrS
Mar 28 at 6:07






Wow, I feel stupid. thank you

– MrS
Mar 28 at 6:07













1 Answer
1






active

oldest

votes


















1
















You did function declaration after the function call. Please follow :PEP8 for more information and secondly if take any input from user, you need to store in some variable to use any way. Here is the code that add item perfectly.



grocery_list = ['salmon', 'beef', 'eggs', 'milk']

def add_to():
s= input("Please enter the item you'd like to add: n")
grocery_list.append(str(s))

print(grocery_list)
question = input("Would you like to add anything to the list?: n")
if question == "yes" or "y" or "Y":
add_to()
else:
print("Enjoy your shopping")



print(grocery_list)


Output :



['salmon', 'beef', 'eggs', 'milk']
Would you like to add anything to the list?:
yes
Please enter the item you'd like to add:
yourhead
['salmon', 'beef', 'eggs', 'milk', 'yourhead']





share|improve this answer



























  • That's another thing I wasn't struggling to figure out. Thank you! Can you explain why I need to add the (str part? Also what's the point of using n to start a new line when I don't need a new line? Is it just good in practice?

    – MrS
    Mar 28 at 6:11











  • Had to wait to be able to do it. Just did both, thanks.

    – MrS
    Mar 28 at 6:14











  • Thanks, Okay n is for good code readability. You need to give n with input() and lets say in future if their is more confusing input user is giving which is long input and mixture of string and int, then you have to give n

    – Rachit kapadia
    Mar 28 at 6:18











  • Okay and the point of (str) is just to let it know that they are inputting text and that it can only be text, correct?

    – MrS
    Mar 28 at 6:23











  • Its depend on developer(you), whether in which form you want to grab input from the user whether in form of int, float, string..etc

    – Rachit kapadia
    Mar 28 at 6:25










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/4.0/"u003ecc by-sa 4.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
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391020%2funresolved-reference-in-defined-function%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









1
















You did function declaration after the function call. Please follow :PEP8 for more information and secondly if take any input from user, you need to store in some variable to use any way. Here is the code that add item perfectly.



grocery_list = ['salmon', 'beef', 'eggs', 'milk']

def add_to():
s= input("Please enter the item you'd like to add: n")
grocery_list.append(str(s))

print(grocery_list)
question = input("Would you like to add anything to the list?: n")
if question == "yes" or "y" or "Y":
add_to()
else:
print("Enjoy your shopping")



print(grocery_list)


Output :



['salmon', 'beef', 'eggs', 'milk']
Would you like to add anything to the list?:
yes
Please enter the item you'd like to add:
yourhead
['salmon', 'beef', 'eggs', 'milk', 'yourhead']





share|improve this answer



























  • That's another thing I wasn't struggling to figure out. Thank you! Can you explain why I need to add the (str part? Also what's the point of using n to start a new line when I don't need a new line? Is it just good in practice?

    – MrS
    Mar 28 at 6:11











  • Had to wait to be able to do it. Just did both, thanks.

    – MrS
    Mar 28 at 6:14











  • Thanks, Okay n is for good code readability. You need to give n with input() and lets say in future if their is more confusing input user is giving which is long input and mixture of string and int, then you have to give n

    – Rachit kapadia
    Mar 28 at 6:18











  • Okay and the point of (str) is just to let it know that they are inputting text and that it can only be text, correct?

    – MrS
    Mar 28 at 6:23











  • Its depend on developer(you), whether in which form you want to grab input from the user whether in form of int, float, string..etc

    – Rachit kapadia
    Mar 28 at 6:25















1
















You did function declaration after the function call. Please follow :PEP8 for more information and secondly if take any input from user, you need to store in some variable to use any way. Here is the code that add item perfectly.



grocery_list = ['salmon', 'beef', 'eggs', 'milk']

def add_to():
s= input("Please enter the item you'd like to add: n")
grocery_list.append(str(s))

print(grocery_list)
question = input("Would you like to add anything to the list?: n")
if question == "yes" or "y" or "Y":
add_to()
else:
print("Enjoy your shopping")



print(grocery_list)


Output :



['salmon', 'beef', 'eggs', 'milk']
Would you like to add anything to the list?:
yes
Please enter the item you'd like to add:
yourhead
['salmon', 'beef', 'eggs', 'milk', 'yourhead']





share|improve this answer



























  • That's another thing I wasn't struggling to figure out. Thank you! Can you explain why I need to add the (str part? Also what's the point of using n to start a new line when I don't need a new line? Is it just good in practice?

    – MrS
    Mar 28 at 6:11











  • Had to wait to be able to do it. Just did both, thanks.

    – MrS
    Mar 28 at 6:14











  • Thanks, Okay n is for good code readability. You need to give n with input() and lets say in future if their is more confusing input user is giving which is long input and mixture of string and int, then you have to give n

    – Rachit kapadia
    Mar 28 at 6:18











  • Okay and the point of (str) is just to let it know that they are inputting text and that it can only be text, correct?

    – MrS
    Mar 28 at 6:23











  • Its depend on developer(you), whether in which form you want to grab input from the user whether in form of int, float, string..etc

    – Rachit kapadia
    Mar 28 at 6:25













1














1










1









You did function declaration after the function call. Please follow :PEP8 for more information and secondly if take any input from user, you need to store in some variable to use any way. Here is the code that add item perfectly.



grocery_list = ['salmon', 'beef', 'eggs', 'milk']

def add_to():
s= input("Please enter the item you'd like to add: n")
grocery_list.append(str(s))

print(grocery_list)
question = input("Would you like to add anything to the list?: n")
if question == "yes" or "y" or "Y":
add_to()
else:
print("Enjoy your shopping")



print(grocery_list)


Output :



['salmon', 'beef', 'eggs', 'milk']
Would you like to add anything to the list?:
yes
Please enter the item you'd like to add:
yourhead
['salmon', 'beef', 'eggs', 'milk', 'yourhead']





share|improve this answer















You did function declaration after the function call. Please follow :PEP8 for more information and secondly if take any input from user, you need to store in some variable to use any way. Here is the code that add item perfectly.



grocery_list = ['salmon', 'beef', 'eggs', 'milk']

def add_to():
s= input("Please enter the item you'd like to add: n")
grocery_list.append(str(s))

print(grocery_list)
question = input("Would you like to add anything to the list?: n")
if question == "yes" or "y" or "Y":
add_to()
else:
print("Enjoy your shopping")



print(grocery_list)


Output :



['salmon', 'beef', 'eggs', 'milk']
Would you like to add anything to the list?:
yes
Please enter the item you'd like to add:
yourhead
['salmon', 'beef', 'eggs', 'milk', 'yourhead']






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 6:08

























answered Mar 28 at 6:02









Rachit kapadiaRachit kapadia

5756 silver badges18 bronze badges




5756 silver badges18 bronze badges















  • That's another thing I wasn't struggling to figure out. Thank you! Can you explain why I need to add the (str part? Also what's the point of using n to start a new line when I don't need a new line? Is it just good in practice?

    – MrS
    Mar 28 at 6:11











  • Had to wait to be able to do it. Just did both, thanks.

    – MrS
    Mar 28 at 6:14











  • Thanks, Okay n is for good code readability. You need to give n with input() and lets say in future if their is more confusing input user is giving which is long input and mixture of string and int, then you have to give n

    – Rachit kapadia
    Mar 28 at 6:18











  • Okay and the point of (str) is just to let it know that they are inputting text and that it can only be text, correct?

    – MrS
    Mar 28 at 6:23











  • Its depend on developer(you), whether in which form you want to grab input from the user whether in form of int, float, string..etc

    – Rachit kapadia
    Mar 28 at 6:25

















  • That's another thing I wasn't struggling to figure out. Thank you! Can you explain why I need to add the (str part? Also what's the point of using n to start a new line when I don't need a new line? Is it just good in practice?

    – MrS
    Mar 28 at 6:11











  • Had to wait to be able to do it. Just did both, thanks.

    – MrS
    Mar 28 at 6:14











  • Thanks, Okay n is for good code readability. You need to give n with input() and lets say in future if their is more confusing input user is giving which is long input and mixture of string and int, then you have to give n

    – Rachit kapadia
    Mar 28 at 6:18











  • Okay and the point of (str) is just to let it know that they are inputting text and that it can only be text, correct?

    – MrS
    Mar 28 at 6:23











  • Its depend on developer(you), whether in which form you want to grab input from the user whether in form of int, float, string..etc

    – Rachit kapadia
    Mar 28 at 6:25
















That's another thing I wasn't struggling to figure out. Thank you! Can you explain why I need to add the (str part? Also what's the point of using n to start a new line when I don't need a new line? Is it just good in practice?

– MrS
Mar 28 at 6:11





That's another thing I wasn't struggling to figure out. Thank you! Can you explain why I need to add the (str part? Also what's the point of using n to start a new line when I don't need a new line? Is it just good in practice?

– MrS
Mar 28 at 6:11













Had to wait to be able to do it. Just did both, thanks.

– MrS
Mar 28 at 6:14





Had to wait to be able to do it. Just did both, thanks.

– MrS
Mar 28 at 6:14













Thanks, Okay n is for good code readability. You need to give n with input() and lets say in future if their is more confusing input user is giving which is long input and mixture of string and int, then you have to give n

– Rachit kapadia
Mar 28 at 6:18





Thanks, Okay n is for good code readability. You need to give n with input() and lets say in future if their is more confusing input user is giving which is long input and mixture of string and int, then you have to give n

– Rachit kapadia
Mar 28 at 6:18













Okay and the point of (str) is just to let it know that they are inputting text and that it can only be text, correct?

– MrS
Mar 28 at 6:23





Okay and the point of (str) is just to let it know that they are inputting text and that it can only be text, correct?

– MrS
Mar 28 at 6:23













Its depend on developer(you), whether in which form you want to grab input from the user whether in form of int, float, string..etc

– Rachit kapadia
Mar 28 at 6:25





Its depend on developer(you), whether in which form you want to grab input from the user whether in form of int, float, string..etc

– Rachit kapadia
Mar 28 at 6:25








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391020%2funresolved-reference-in-defined-function%23new-answer', 'question_page');

);

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







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해