#๐ Help me
21 messages ยท Page 1 of 1 (latest)
@pine pelican
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.
Click here to see this code in our pastebin.
let's rubber duck this one a bit
tell me what you think the function shop_script() is doing and how it's doing it
Shop_script() will calculate when I put 1 in answer_shopchoice and save it to coin in the first line
@tribal forge
not quite
def is used to define a new function in python
after that comes the function signature which ends with the colon
the first thing in the function signature is the name of the function
then inside the parentheses comes any arguments to the function
arguments that is sent in to the function is assigned to new variables with the names in the order as they appear in the function signature
those new variables are only valid within that function and is referred to as local variables or that they are in the local scope
@pine pelican as you are creating a new variable with the name coin in the function signature you can't get at the global variable (in a "normal" way) with the same name as it is now "overshadowed" by the local variable with the same name, as long as that local variable is valid (in scope, that means, as long as you are in the function. there is some ways to get around that, but that is outside of the scope for this help post)
if you use different names for the two variables you can easily get at the global variable by just using it normally, if you also want to change its value from within the function you will have to declare the variable as global within the function so that you are allowed to set it to a new value
another thing that is going wrong here is that you are using returnwithout assigning the returned data to a variable at the place where you are calling the function
if you return coin you don't really have to mess with global or the global variable at all within the show_script function and you can keep that code just as it is without even changing the variable name
to assign the returned value back to the coin variable you would only need to change your code so that
if "1" in answer_shopchoice:
shop_script(coin)
```becomes
```py
if "1" in answer_shopchoice:
coin = shop_script(coin)
```and you would need to add another line to your code inside somewhere close to the top of the `main_script` function, something like this
```py
global coin
but you really need to work on the formatting of your code, especially when it comes to the indentation, as indentation matters a great deal in python and it can get messy if you're not consistent
to start with you should follow python best practices and use 4 spaces per indentation level
the line
while coin < 0:
```isn't doing what you probably think it's doing, as it will never have the chance to loop a single time, just run the code once if the condition is met, so it's just doing the same job as an `if` conditional statement would do here
speaking of if conditional statements, you probably want to be using
if ...:
...
elif ...:
...
elif ...:
...
```here (and in several other places in your code) instead of
```py
if ...:
...
if ...:
...
if ...:
...
```for `if` statements that belongs to the same "group" of conditionals
and you also using in in your conditional statements instead of using ==, which is what you really should be using here
It's work but had new problem
If coin=0 and I buy thing,
It's results negative object
for example
you have 0 coin and buy strong poison with 30 coin
It's results -30
@tribal forge
How I prevent it?
Guy?
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.