How do I subtract or add in a lists?
When I run the program below I get the message
print int(pool-strength)
TypeError: unsupported operand type(s) for -: 'list' and 'int'

# Character Development Dungeons and Dragons
# pool are the total points that I can use.
pool = [30]

choice = None

while choice !="0":
    print \
    """

    Character Development

    0 - Exit
    1 - Strength
    """
    
    choice = raw_input("Choice: ")
    print
    # exit
    if choice == "0":
      print "Good-bye."

    # Strength points
    elif choice == "1":
      strength = 0
      strength = int(raw_input("How much strength points do you want?: "))
      print int(pool-strength)

    # some unknown choice
    else:
      print "Sorry, but", choice, "isn't a valid choice."

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

Recommended Answers

All 5 Replies

you are trying to do [30] - int,

perhaps you want to get the value from the list, not the list itself.

It should be
pool = 30
The [] turn pool into a list and you want an integer variable.

Thanks. It works now with that change.
Just curious if I had left pool = [30] is it impossible to use operands for lists? Such as -, +, *, / if there is a way what is the correct method on doing so?

Thanks. It works now with that change.
Just curious if I had left pool = [30] is it impossible to use operands for lists? Such as -, +, *, / if there is a way what is the correct method on doing so?

Yeah you can do that, but you have to specify which value in the list you're talking about. In this case you could do something like
pool[0] = pool[0] - 10 or
pool[0] -= 10.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.