Jun-12-2018, 09:16 PM
Hello!
Since python has a min(array) command I tried to make one manually. However I ran into a problem. Here is my code (file name is "listan.minimi.py"):
Here is what I get out:
File "listan.minimi.py", line 7
arr_size = len(arr)
^
IndentationError: expected an indented block
I tried replacing tabs with spaces but still I don't seem to understand the problem here. Thanks!
Since python has a min(array) command I tried to make one manually. However I ran into a problem. Here is my code (file name is "listan.minimi.py"):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import sys arr = [ 1 , 2 , 3 ] def print2Smallest(arr): arr_size = len (arr) if arr_size < 2 : print "invalid output" return first = second = sys.maxint #antaa muuttujille first ja second suurimman mahdollisen lista-arvon pythonissa for i in range ( 0 , arr_size) if arr(i) < first: second = first first = arr[i] elif (arr[i]<second and arr[i] = !first): second = arr[i]; if (second = = sys.maxint): print "No second smallest element" else : print 'The smallest element is' , first 'and' \ ' second smallest element is' , second |
File "listan.minimi.py", line 7
arr_size = len(arr)
^
IndentationError: expected an indented block
I tried replacing tabs with spaces but still I don't seem to understand the problem here. Thanks!