My code doesn't seem to run i get a error message but i don't see a problem maybe someone can

Joined
Jul 25, 2024
Messages
21
Reaction score
1
Code:
# This is a small text based adventure game
# Meant to test my python skills
# I will release this to the public if I decide it's good enough
# Starting date and time 2/5/2025 - 9:44 PM
class game():
    def __init__(self):
        self.player_info()
        self.cuss_checker()
        self.main()
    def player_info(player_age=10, player_name="Chris Jones"):
        player_name = input(cuss_checker(player_name))
        player_age = int(input(f"What is your age {player_name}?"))
        return {"age": player_age, "name": player_name}
    def cuss_checker(word):
        word = word.lower()
        cuss_words = ["various cusswords"]
        while word in cuss_words:
            print("Sorry that is not allowed")
            word = input("Please try again ")
            continue
        else:
            print("That is allowed thank you!")
            return word
    def main(player_age, player_name):
        game_running = True
        print("Welcome to a small text based adventure")
        while game_running:
            start_game = input("Would you like to play this game? (yes/no): ").lower()
            if start_game != "yes":
                print("Thank you for considering this game, have a nice day")
                game_running = False
                continue
            if player_age < 10:
                print(f"I am sorry {player_name}, you are not old enough to play this game please try again after your tenth birthday ")
                continue
            else:
                print(f"Welcome {player_name} to the game, let's get the story started!")
                
                play_again = input("Would you like to play again? (yes/no): ").lower()
                if play_again != "yes":
                    print("Thank you for playing this game, have a nice day")
                    game_running = False
                    continue
                else:
                    print("Thanks for playing my game, have a nice day")
                    game_running = False



game()
i edited out some of the code for obvious reasons but this is pretty much the same code
 
Joined
Dec 10, 2022
Messages
114
Reaction score
26
Please post error message
You call self.main without args yet you define it with args.
 
Joined
Feb 12, 2025
Messages
9
Reaction score
0
# I don't know, I think I need to see the cuss_words. it may have something to do with this....
#(Just kidding. One way to hide this is to just change the variable, cuss_words = blueberries. Also, have you heard of caesar cypher? If you use this on your cuss_words, when people look at it, they will see just a bunch of random letters, they wouldn't even know what it is.)


#I don't know what you are trying to do, but I did notice some things:

#one thing I noticed was that you were not using self. in some things.

1. In the init function, the player_name and player_age should be defined, like this: self.player_name = "blah blah"
2. Get rid of the cuss_checker() in the init function, there already is one in the player_info function.
3. One of the errors says, "game.main() missing 1 required positional argument: 'player_name'" This means that the caller, from init, is missing the 'player_name' argument. But when you look at self.main(), you didn't put ANYTHING in it. So, why is it saying ONLY the 'player_name' is missing? That's because of the self. function. When you call a function using self., like self.main(), it input the self into the def main(player_age, player_name). The first one is player_age, which = self. When you put player_name into the init main, like this: self.main(player_name), now def main(player_age, player_name) equals: def main(player_age=self, player_name="blah blah"). How do we fix the self-age problem? simple, add the word self before the age: def main(self = self, player_age=0, player_name="blah blah"), which now looks better, def main(self = self, player_age=0, player_name="blah blah"). DON'T forget to add player_age into the init main() too. self.main(player_age, player_name).
 
Joined
Feb 12, 2025
Messages
9
Reaction score
0
Code:
class game():
    def __init__(self):
        self.player_name = ""
        self.player_age = 0
        self.player_info()
        self.main(self.player_age, self.player_name)

    def player_info(self):
        player_name = input("What is your name?: ")
        player_name = self.cuss_checker(player_name)
        player_age = int(input(f"What is your age, {player_name}?: "))
        self.player_name = player_name
        self.player_age = player_age

    def cuss_checker(self, word):
        if word == 0:
            print()
        else:
            word = word.lower()
            cuss_words = ["sorry"]
            while word in cuss_words:
                print("Sorry that is not allowed")
                word = input("Please try again ")
                continue
            else:
                print("\nThat is allowed thank you!\n")
                return word

    def main(self, player_age, player_name):
        game_running = True
        print("Welcome to a small text based adventure")
        while game_running:
            start_game = input("Would you like to play this game? (yes/no): ").lower()
            if start_game != "yes":
                print("Thank you for considering this game, have a nice day")
                game_running = False
                continue
            if player_age < 10:
                print(
                    f"I am sorry {player_name}, you are not old enough to play this game please try again after your tenth birthday ")
                continue
            else:
                print(f"Welcome {player_name} to the game, let's get the story started!")

                play_again = input("Would you like to play again? (yes/no): ").lower()
                if play_again != "yes":
                    print("Thank you for playing this game, have a nice day")
                    game_running = False
                    continue
                else:
                    print("Thanks for playing my game, have a nice day")
                    game_running = False


game()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top