0
What's wrong with this code?
x=[23,45,65] y=[24,46,66] print('min',min(x[:1],y[:1]))
3 Answers
+ 1
There is nothing wrong with your code it's working fine. What you code is actually doing finding the minimum element value in two lists x and y
x [:1] this line of code is giving range to list x. If you put x [:6] it means you are giving a range to list from 0 to 6. List will go through from index 0 to 6
print('min',min(x[:1],y[:1]))
This statement will print minimum number in these list which is 23
+ 1
There's no way to tell since you've omitted the code's intent (the definition of a 'logical' error; but humans can guess when computers can't). Here's what it does:
>>> x=[23,45,65]
>>> y=[24,46,66]
>>> print('min',min(x[:1],y[:1]))
min [23]
If you check the inside steps:
>>> print(x[:1])
[23]
>>> print(y[:1])
[24]
>>>
It's a human guess this is a logical error since you're only comparing the first value in each list. The computer doesn't care (but it can be made to with Asserts).
+ 1
@Waqas Asghar
There's nothing wrong with the syntax; it's probably a logical error.
There's no range() call. The : operator omits the indicated value ( :6 is 0-5). The minimum printed is between 2 values (those two at index 0), not all 6.
Like...this minimum should probably be 0:
>>> x=[23,45,65,1,2,3]
>>> y=[24,46,66,0,190,7]]
>>> print('min',min(x[:1],y[:1]))
min [23]
Unless the OP omitted a loop to return the minimum at each index (0-5, here).



