for loop - Use value of a variable as counter in python 3 -


i want take input user , and store in variable, lets k. use k counter for loop.

while i<k: doesn't work! code:

k= input('number of points:') p=[] i=0 while i<k: x=float(input('enter value=')) p.append(x) i=i+1 

output:

number of points:3 traceback (most recent call last): file "/home/ramupradip/tes.py", line 4, in <module> while i<k: typeerror: unorderable types: int() < str() 

i tried using range

for in range(1,k) 

which gave me error: traceback (most recent call last): file "/home/ramupradip/reflect.py", line 6, in in range(1,k): typeerror: 'str' object cannot interpreted integer

read input this:

k = int(input('enter counter: ')) 

... guess forgot convert number int, it's impossible tell if don't show relevant code. other that, looping constructs shown in question should work fine, first 1 preferred in python, careful indexes:

for in range(1, k+1):     # 

equivalently:

i = 1 while <= k:     #     += 1 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -