#๐Ÿ”’ Looking for help on this piece of code

17 messages ยท Page 1 of 1 (latest)

chrome timber
#

I feel like a dumbass ive been stuck on this thing for a while (on the bottom biscuittime is not defined)

distant oxideBOT
#

@chrome timber

Python help channel opened

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.

restive grove
#

where do you define BiscuitTime?

chrome timber
#

thats the thing idk where i should

#

im sorry if i sound stupid i started python recently

restive grove
#

we all start somewhere

#

do you understand scope?

chrome timber
#

no ๐Ÿ˜ญ

#

i dont even think i learned that yet

restive grove
#
def foo():
  my_variable = 42
  print(my_variable)

in that code above my_variable is only available in the foo function. Outside of it, it is not available. That's the basics of scope. Another way to think of it is that every level of indentation is a new level of scope, and you can't use a variable in the outer scope

#

while there are better ways to do it, since you're learning you can do something like this: ```py

my_variable = 42

def foo():
my_variable = "something else"

if ...:
my_variable = "a third thing"

restive grove
#

sure thing

#

if you want to do further reading on it, the keywords for that are global variable and global scope

chrome timber
#

alr

distant oxideBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.