+ 1

Same python code different result in Solo python code playground

items = [2, 4, 6, 8, 10, 12, 14] middle = int(len(items) // 2) print(items[middle]) I pasted the above to code playground. After run, it shows ā€œno outputā€. Click run again, it shows ā€œ8ā€. Every click will show either ā€œno outputā€ or ā€œ8ā€. Is it the code issue or solo editor issue? Thanks!

21st Jan 2021, 1:03 PM
Hugo So
Hugo So - avatar
5 Answers
+ 2
"items" is a keyword in python so you can't use it as variable name. #CODE: num = [2, 4, 6, 8, 10, 12, 14] middle = int(len(num) // 2) print(num[middle])
21st Jan 2021, 1:05 PM
minirkk
minirkk - avatar
+ 1
RKK thanks very much. I will avoid using Python keyword as variable. The above code is from Solo Python 3 course practise which pre-sets ā€œitemsā€ as variable in the practise.
21st Jan 2021, 1:14 PM
Hugo So
Hugo So - avatar
+ 1
Can you give me the link where items is used as variable name, if possible?
21st Jan 2021, 1:17 PM
minirkk
minirkk - avatar
0
better to use elem vs item and lst vs list, and st vs str
21st Jan 2021, 1:18 PM
Shadoff
Shadoff - avatar
0
RKK 26.4 ā€œthe middle elementā€ practise. just found out I misunderstood the question. But anyway, it does pre-set ā€œitemsā€ as var.
21st Jan 2021, 1:24 PM
Hugo So
Hugo So - avatar