| | |
Subtracting values w/list
![]() |
•
•
Join Date: Nov 2008
Posts: 56
Reputation:
Solved Threads: 0
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'
When I run the program below I get the message
print int(pool-strength)
TypeError: unsupported operand type(s) for -: 'list' and 'int'
python Syntax (Toggle Plain Text)
# 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: ") # 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.")
you are trying to do [30] - int,
perhaps you want to get the value from the list, not the list itself.
perhaps you want to get the value from the list, not the list itself.
•
•
Join Date: May 2008
Posts: 662
Reputation:
Solved Threads: 112
Python lists support several methods for example: append, count, extend, index, insert, pop, remove, reverse, sort
http://www.letmegooglethatforyou.com/?q=Python+List
http://www.letmegooglethatforyou.com/?q=Python+List
•
•
Join Date: Nov 2007
Posts: 148
Reputation:
Solved Threads: 33
•
•
•
•
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?
pool[0] = pool[0] - 10 or
pool[0] -= 10.
![]() |
Similar Threads
- plane sweepin (C++)
- Prolog testing values of a variable (Legacy and Other Languages)
- Please Help!!! (C)
Other Threads in the Python Forum
- Previous Thread: Help with this code
- Next Thread: Homework Help
Views: 996 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for Python
application array beginner c++ c/c++ change character class client code command compression convert count create csv ctypes cx-freeze database dictionary django dll error examples excel exe extensions fdlib file float format framework ftp function graphics gui homework image images import input library line linux list lists logging loop loops microcontroller mouse mysql mysqldb number numbers output parse parsing path pointer port prime processing program programming py2exe pygame pygtk pyqt python random raw_input recursion recursive redirect remote scrolledtext server socket ssh stdout string strings syntax table terminal text thread threading tkinter transparency tuple tutorial ubuntu unicode variable variables web windows wxpython






