0
In a for in C, we define "beginning, end and step increment". I know that in Python it is not so. I saw that it is called foreach. I wish the end of mine for is defined by the user. And that, at each iteration until the end of the is, a value is requested from the user and saved in an array.
I tried to:
num_tracos = raw_input()
tracos_treino = np.arange(100)
for i in num_tracos:
print "Digite o traco", i+1, " para o treinamento"
tracos_treino[i] = raw_input()
I also tried a while, but it didn’t work because it never ends (it actually makes a mistake when it reaches entry 101, because it doesn’t fit in the vector anymore, but if it weren’t for that, it would be infinite) :
num_tracos = raw_input()
tracos_treino = np.arange(100)
i=0
while i < num_tracos :
print "Digite o traco", i+1, " para o treinamento"
tracos_treino[i] = raw_input()
i = i+1
I’ve always heard a better for that a while, unless you’re going to iterate initamente (ie never). I read this in "Learn Python The Hard Way".
Anyway, neither one of you is working the way I’d like.
I see you’re wearing
raw_input
. Which python version you are using ?– Isac