Question: Python program help, indentation issues i have an input.txt and output.txt file and i think my indentations are screwed up for the program below. thank
Python program help, indentation issues
i have an input.txt and output.txt file and i think my indentations are screwed up for the program below. thank you for the help
input.txt
4 1 8 3 9
5 7 2 4 9 4
code:
# Function to do insertion sort
def insertionSort(arr):
# Traverse through 1 to len(arr)
for i in range(1, len(arr)):
key = arr[i]
# Move elements of arr[0..i-1], that are
# greater than key, to one position ahead
# of their current position
j = i-1
while j >=0 and key
arr[j+1] = arr[j]
j -= 1
arr[j+1] = key
# Driver code to test above
def main():
arr = list() #Creating array list to store the number read from file
f=open("data.txt","r");
o=open("insert.txt","w");
list1=f.readline().split();
list2=f.readline().split();
l1=[]
l2=[]
for val in list1:
l1.append(int(val))
del l1[0]
print("Insert Sort");
l1=insertionSort(l1)
#print(insertionSort(l1))
insertionSort(l1)
#insertionSort(l1)
print(l1)
o.write(str(l1) + ' ')
for val in list2:
l2.append(int(val))
del l2[0]
l2=insertertionSort(l2)
print (l2)
o.write(str(l2) + ' ')
f.close()
o.close()
main()

main.pyE saved # Function to do insertion sort 2 def insertionsort (arr): through 1 to len(arr) # Traverse for i in range(1, len(arr)): # Move elements of arr[e.. i-1], that are # greater than key, to one position ahead # of their current position 1e 12 13 14 15 16 17 18 # Driver code to test above 19 2e def main): 21 while j e and key
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
