Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7840569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:49:55+00:00 2026-06-02T15:49:55+00:00

I am completing a simple programming exercise (I am still new) where I am

  • 0

I am completing a simple programming exercise (I am still new) where I am creating a character profile by allocating 30 points to 4 different character attributes. Program features are: show current profile, create a new profile, or change existing profile. First and second feature work fine, but there is problem with the last: the program is meant to unpack the nested list item (attribute + allocated score), ask for a new score, take the difference between the old and new and change the number of available points in the pool accordingly. Finally, add a new entry to the list (attribute + newly allocated score) at position 0 and then delete the entry at position 1, which should be the old entry for this attribute. Loop through the list, and done. However, once you execute the code you will see it won’t work. Please see below the complete code:

options = ["Strength", "Health", "Wisdom", "Dexterity"]
profile = []
points = 30

choice = None
while choice != "0":

    print(
        """
    CHARACTER CREATOR PROGRAM

    0 - Exit
    1 - See current profile
    2 - Build new profile
    3 - Amend existing profile

    """
        )

    choice = input("Please choose an option: ")
    print()

    if choice == "0":
        print("Good bye.")
    elif choice == "1":
        for item in profile:
            print(item)
        input("\nPress the enter key to continue.")
    elif choice == "2":
        print("You can now equip your character with attributes for your adventures.")
        print("You have",points,"points to spent.")
        print("Now configure your character: \n")
        #Run the point allocation loop
        for item in options:
            point_aloc = int(input("Please enter points for " + str(item) + ":"))
            if point_aloc <= points:
                entry = item, point_aloc
                profile.append(entry)
                points = points - point_aloc
                print("\nYour current choice looks like this: ")
                print(profile)
                input("\nPress the enter key to continue.")
            else:
                print("Sorry, you can only allocate", points," more points!")
                print("\nYour current choice looks like this: ")
                print(profile)
                input("\nPress the enter key to continue.")
        print("\nWell done, you have configured your character as follows: ")
        for item in profile:
            print(item)
        input("Press the enter key to continue.")
    elif choice == "3":
        print("This is your current character profile:\n")
        for item in profile:
            print(item)
        print("\nYou can change the point allocation for each attribute.")
        for item in profile:
            point_new = int(input("Please enter new points for " + str(item) + ":"))
            attribute, points_aloc = item
            diff = points_aloc - point_new
            if diff >0:
                points += diff
                print("Your point allocation has changed by", -diff,"points.")
                print(diff,"points have just been added to the pool.")
                print("The pool now contains", points,"points.")
                entry = item, point_new
                profile.insert(0, entry)
                del profile[1]
                input("Press the enter key to continue.\n")
            elif diff <0 and points - diff >=0:
                points += diff
                print("Your point allocation has changed by", -diff,"points.")
                print(-diff,"points have just been taken from the pool.")
                print("The pool now contains", points,"points.")
                entry = item, point_new
                profile.insert(0, entry)
                del profile[1]
                input("Press the enter key to continue.\n")
            elif diff <0 and points - diff <=0:
                print("Sorry, but you don't have enough points in the pool!")
                input("Press the enter key to continue.\n")
    else:
        print("Sorry, but this is not a valid choice!")
        input("Press the enter key to continue.\n")

input("\n\nPress the enter key to exit.")

Note: You need to create the profile first to run the changes.

Thanks in advance for your help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:49:57+00:00Added an answer on June 2, 2026 at 3:49 pm

    As the comments to your question indicate, you haven’t asked your question in the best way. However, I see what’s wrong with it. I could show you how to fix your current code, but the truth is that the best way to fix it is to rewrite it completely. As you do so, you should adopt the following strategies:

    1. Break your code up into parts. In this case, I would advise you to create several different functions. One could be called main_loop, and would contain the logic for looping through the menu. It wouldn’t contain any of the code for updating or displaying profiles. Instead, it would call other functions, display_profile, build_profile, and amend_profile. Those functions would accept variables such as options, profile, and points, and would return values such as options and points. This will enormously simplify your code, and make it much easier to test and debug. Here’s an example of what main_loop might look like:

      def main_loop():
          options = ["Strength", "Health", "Wisdom", "Dexterity"]
          profile = []
          points = 30
      
          choice = None
          while choice != "0":
              print(menu_string)   #define menu_string elsewhere
              choice = input("Please choose an option: ")
              print()
      
              if choice == "0":
                  print("Good bye.")
              elif choice == "1":
                  display_profile(profile)
              elif choice == "2":
                  profile, points = build_profile(options, profile, points)
              elif choice == "3":
                  profile, points = amend_profile(profile, points)
              else:
                  print("Sorry, but this is not a valid choice!")
                  input("Press the enter key to continue.\n")
      
          input("\n\nPress the enter key to exit.")
      

      See how much nicer this is? Now all you have to do is define the other functions. Something like…

          def build_profile(options, profile, points):
              # insert logic here
              return profile, points
      

      Another advantage to this approach is that now you can test these functions individually, without having to run the whole program.

    2. Use the correct idioms for list modification. Modifying a list while iterating over it takes special care, and in some cases (such as when you change the length of the list by removing or adding items you’ve already iterated over) it won’t work at all. There are ways to do what you try to do to profile, but for a beginning programmer I would recommend something much simpler: just create a new list! Then return that list. So in your amend_profile function, do something like this:

          def amend_profile(profile, points):
              # other code ...
              new_profile = []
              for item in profile:
                  attribute, points_aloc = item
                  # other code ...
                  new_proflie.append(entry)
              # other code ...
      
              return new_profile, points
      

      Note also that this is where one of your main bugs is; you create an entry containing (item, point_new) instead of (attribute, point_new), so your new tuple has an item tuple inside it, instead of a lone attribute string as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want users to receive 'points' for completing various tasks in my application -
I'm a designer and brand new to programming. I have just opened my localhost
I'm considering two different ways of completing the same task of displaying dynamic HTML
I'm newbie to Game programming. I'm trying to develop a simple shooting game. The
I have one simple program of wsgi. from wsgiref.simple_server import make_server import time def
I am new to web programming, coming from a video game development background (c++),
So, I'm trying to make a simple multi-threaded program that validates the Collatz Conjecture
Need some help for creating a File and String search engine. The program needs
I am completing my first database project which aims to build a simple discussion
I am very new to programming and Objective-C and I am trying to work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.