I am creating a python program that creates an xhtml table for websites based on a variable value.
please look at the following two codes. The second one does not work.
rows = int(input('How many rows would you like? '))
for i in range(rows):
print 'lol'
rows = raw_input('How many rows would you like? ')
int(rows)
for i in range(rows):
print 'lol'
even though i have properly stated that the rows variable is being changed to an integer, why doesn’t the range function accept this, and treat it as as integer?
No, rows is not being changed to an integer. Just applying
int(rows)onrowsdoes not change thestrobjectrowstoint. But it returns anintegerobject.You would either need to store the return value in a variable, and use it. Or, directly use it in
rangefunction.The above code should be: –