[Tutor] role playing game - help needed
Robert Sjöblom
robert.sjoblom at gmail.com
Tue Dec 7 13:37:23 CET 2010
>> attributes["strength"] = input("\nHow many points do you want to
>> assign to
>> strength?: ")
>>
>> Please let me know if this isn't advisable. It seems to work on the
>> surface.
>
> Close, but remember that input() returns a string. You need numbers
> so you need to convert strings to integers.
Actually, input() only accept integers, consider the following:
>>> input("input: ")
input: d
Traceback (most recent call last):
File "<pyshell#46>", line 1, in <module>
input("input: ")
File "<string>", line 1, in <module>
NameError: name 'd' is not defined
if you assign d to an integer, input() will accept it, however:
>>> d = 7
>>> input("input: ")
input: d
7
>>> input("input: ")
input: 7
7
>>> help(input)
Help on built-in function input in module __builtin__:
input(...)
input([prompt]) -> value
Equivalent to eval(raw_input(prompt)).
I've been told to use input() if I know that I'll only get integers,
and raw_input() for "everything." Would you say it's better to use
raw_input() for everything and convert as necessary?
best regards,
Robert S.
More information about the Tutor
mailing list