0

I am stucked at this python program please help me [solved]

list=[5,5,8,2,9] jh=list.index(9) print(jh) list[4]=40000 print(list[4]) co=len(list) #this line is not working print("length of list is: "+co) list.append(299999) print(list[5])

20th Nov 2021, 2:27 AM
Samaan Sayed
4 ответов
+ 4
#Try this one list=[5,5,8,2,9] jh=list.index(9) print(jh) list[4]=40000 print(list[4]) co=len(list) print("length of list is: ",co) list.append(299999) print(list[5])
20th Nov 2021, 2:36 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
Anjali kaur len function returns int so co will be a type of int But "length of list is:" is a string so you can't directly concat int with string For this you need to cast co with str function print ("length of the list is: " + str(co)) #this will now work
20th Nov 2021, 3:23 AM
A͢J
A͢J - avatar
+ 3
20th Nov 2021, 2:55 AM
Samaan Sayed
+ 2
Anjali, From this moment on, try not to use Python built-in class/function names as variable's name. Here you define a `list` object named <list>. But `list` itself is a class name, so please choose a different name for the variable. Use of `list` as variable name shadows the original one, rendering it unusable. list = [ 5, 5, 8, 2, 9 ] another_list = list( range( 11 ) ) # use built-in function list() # to create a `list` object # error: <list> had been redefined # it no longer is a callable
20th Nov 2021, 7:06 AM
Ipang