I have a bit of experience with python. I can write bare basic functions and use basic algorithms and stuff. I'm trying to make a function that requires input to work properly. Basically an npc would ask the player where their allegiance lies. I'm on vs studio code and every time I attempt to run it, it just spits out the prompt for the input and one of the answer choices with no input from me. I have the microsoft python extensions plus code runner. I'm kinda at a loss for what to do here.
#๐ Inputs not working on vs code
39 messages ยท Page 1 of 1 (latest)
@lime belfry
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
code goes as follows
Save your code
And also, .lower is a method, you need to call it
Like your_answer.lower()
Thank you
Its still not allowing me to input anything
I just got an error message like NameError: your_answer is not defined when it's not even giving me the prompt for the input
can you paste the code here?
your_answer = input("Who do you swear allegiance to?")
def ilthias_law():
if your_answer.lower() == 'ilthias':
print("Understood go forth")
else:
print("You are not welcome here, Begone!")
ilthias_law()````
you just needed round brackets
that was mentioned already above
I know but thought I'd post the working code
but the error they're showing doesn't appear to be from that code above, so it would be nice to see the latest from them
Hold on sorry I was taking care of getting some food
also I'd recomend avoiding the global scope with variables where possible so something like this ```py
def ilthias_law(your_answer):
if your_answer.lower() == 'ilthias':
print("Understood go forth")
else:
print("You are not welcome here, Begone!")
def main():
your_answer = input("Who do you swear allegiance to?")
ilthias_law(your_answer)
if name == "main":
main()
```
your_answer = input("Who do you swear your allegiance to?")
def ilthias_law():
if your_answer.lower() == "ilthias":
print("Understood, go forth")
else:
print("You are not welcome here, Begone!")
ilthias_law()
thanks bot
!e
your_answer = "test"# input("Who do you swear your allegiance to?")
def ilthias_law():
if your_answer.lower() == "ilthias":
print("Understood, go forth")
else:
print("You are not welcome here, Begone!")
ilthias_law()
:white_check_mark: Your 3.13 eval job has completed with return code 0.
You are not welcome here, Begone!
So what does global scope mean?
Did you properly save the file?
I wouldn't expect a NameError from this, but Pixler is right with their solution. You shouldn't be accessing global variables that way
Yeah
you shouldn't create a variable outside of a function and then access it from within the function
there are reasons to break this rule, but this is not a situation where you should
Ahhhhh that makes sense, so general rule when using variables that are specific to a function you should define them within the function
yes exactly
or this is where we can introduce parameters, like Pixler's example shows
Take a screenshot of the whole VSCode
this little white dot means the file is unsaved
Alright, hold on I'm gonna just put the variable into the function itself
It worked
Thank you all
I anticipate that I'm probably gonna have more questions as I learn more python lol. But thank you all for your help
Np, that's all part of the learning process ๐
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.