dimanche 10 juillet 2016

Variable not being recognized as integer in Python?


Here is my code:

print "How many frames do you want?"
f = raw_input()
print f
frames = 'abcdefghijklmnopqrstuvwxyz'

if f > 0:
    frames = frames[:f]
    print frames

Then when I run it (my input was 2), I get this error where the variable f is not being recognized as an int, even though when I print it, my input printed an int (2).

Here's the error message: Traceback (most recent call last): File "melissa.py", line 11, in frames = frames[:f] TypeError: slice indices must be integers or None or have an index method...

So, f is 2, but I can't use it to slice the string??


Aucun commentaire:

Enregistrer un commentaire