Huge function problem

skill_point_count = 10
skill_dictionary = {"strength": 0, "agility": 0, "magicka": 0}


def spend_skills(skill_points):
    print("""Type s if you want to spend your skill on strength, 
Type a if you want to spend your skill on agility, 
Type m if you want to spend your skill on magick""")
    while skill_points > 0:
        spend = input(f"You have {skill_points} skill points left")
        if spend.lower() == "s":
            skill_dictionary["strength"] += 1
            print("Skill added for strength")
        elif spend.lower() == "a":
            skill_dictionary["agility"] += 1
            print("Skill added for agility")
        elif spend.lower() == "m":
            skill_dictionary["magicka"] += 1
            print("Skill added for magicka")
        else:
            print("Try again please")
            skill_points += 1
        skill_points -= 1

    print(skill_points)


spend_skills(skill_point_count)
print(skill_dictionary.items())
print(skill_point_count)

OUTPUT:

Type s if you want to spend your skill on strength, 
Type a if you want to spend your skill on agility, 
Type m if you want to spend your skill on magick
You have 10 skill points lefts
Skill added for strength
You have 9 skill points lefts
Skill added for strength
You have 8 skill points left
Try again please
You have 8 skill points lefts
Skill added for strength
You have 7 skill points lefts
Skill added for strength
You have 6 skill points left
Try again please
You have 6 skill points leftss
Try again please
You have 6 skill points left
Try again please
You have 6 skill points lefts
Skill added for strength
You have 5 skill points lefts
Skill added for strength
You have 4 skill points left
Try again please
You have 4 skill points lefts
Skill added for strength
You have 3 skill points leftss
Try again please
You have 3 skill points left
Try again please
You have 3 skill points lefts
Skill added for strength
You have 2 skill points lefts
Skill added for strength
You have 1 skill points lefts
Skill added for strength
0
dict_items([('strength', 10), ('agility', 0), ('magicka', 0)])
10

How do I make it so skill_point_count equals 0 after executing the function spend_skills? I have been stuck on this for over 2 hours now and I just can’t. I feel like a complete idiot, thanks for the help.

1 Like

Have your function return skill_points
Assign skill_point_count to the result of calling spend_skills

3 Likes

yeah I know how to do this, but I want to change skill_point_count to zero in the function and export it out of the function as well

You pass into the function skill_point_count it has the value of 10
Your function does its magic to that value of 10 under the name of skill_points
By the end of your functions magic the value skill_points has reached zero
You want the value skill_point_count to equal the value of skill_points
SO your function should return skill_points
Call your function - while mutating the value skill_point_count
skill_point_count = spend_skills(skill_point_count)
pass spc into the spend skills function and assign it equal to the value the function spits out

1 Like

I had to shout very loudly now, I just realized that I have to call the function at least once, that means I can do the addition to the variable while calling it. Wow, wow, I am literally so stupid.
Bless you man. Bless you.

1 Like