I am making a project, on Replit, that makes money, not in real life. I want the 'wheat_seads', 'melon_seeds', 'pumpkin_seeds', 'wheat', 'melon', 'pumpkin' to be available in and out of functions and be changed in different functions. I tried to put these variables in and out of the 'farm_command' to remove the 'Syntax error', but it doesn't work. If you can also, improve this piece of code...
from replit import db
#This function is when 'help' command is run
def help_command():
print("So you need help...")
print("I am happy to help!")
print("1. 'help'")
print("2. 'farm'")
print("3. 'harvest'")
#This functon is when 'farm' command is run
def farm_command():
global wheat_seeds = 1
global melon_seeds = 1
global pumpkin_seeds = 1
global wheat = 0
global melon = 0
global pumpkin = 0
print("What seed do you want to farm?")
farm_seed = input("Seed: ")
farm_seed = farm_seed.lower()
if farm_seed == "wheat_seeds":
print("You planted " wheat_seeds " wheat seed/s")
wheat_seeds -= wheat_seeds
#The user's cash amount
db["User"] = {
"wallet":0,
"bank":0
}
#This is the users inventory
inventory = [wheat_seeds, melon_seeds, pumpkin_seeds, wheat, melon, pumpkin]
#This is prompted to ask the user what command should be run
command = input("Command: ")
#This checks which command is inputted and runs the respective command
if command == "help":
help_command()
elif command == "farm":
farm_command()
CodePudding user response:
You can't assign a value directly when you defining a global variable. Try it like this:
global wheat_seeds
wheat_seeds = 1
and so on...