I'm trying to use the range function with a variable assigned to an input. I have a .csv file and I'm trying to have it so that when the user gives their input as a number from 1-233 that the range will pick that line from the spreadsheet and print out the integer from only the first cell. However I can only get it to cycle down to the last line of the spreadsheet, regardless of what the input is. Below is the code.
var=input('Please give a number >0 and <= the number of students -->')
for line in file:
line=range(var)
print(line)
How can I get it to only output the line that the user inputs?
line=range(var)is doing? In any case, you are iterating through the entire file:for line in file:... perhaps you meant to do something else with that...csvfile might be better done with thepandasmodule