This is my pseudo code that i have to translate into python
A=99
LENGTH= LENGTH(list)
LIST= 92 50 26 82 73
for P in range 0 to LENGTH-1
IF LIST[P] <A THEN
A=LIST[P]
B=P
ENDIF
ENDFOR
IF B < LENGTH THEN
for P in range B to LENGTH -2
LIST[P] = LIST[P+1]
ENDFOR
ENDIF
LENGTH=LENGTH-1
LIST[LENGTH]=NULL
My attempt at coding done below, the code is meant to remove the lowest value from the LIST
a = 99
list=[92,50,26,82,73]
for p in range (0,len(list) - 1):
if list[p] < a :
a = list[p]
b = p
print (list) #I just added this to see what was happening
if b < len(list):
for p in range (b,len(list)-2):
list[p]=list[p]+1
list=len(list)-1
print (list)
#I just added this to see what was happening
I have wrote the code above and it doesnt remove the lowest value
You are really close, here are the corrections:
A = 99
l = [92, 50, 26, 82, 73]
LENGTH = len(l)
for P in range(LENGTH):
if l[P] < A:
A=l[P]
B=P
if B < LENGTH:
for P in range (B, LENGTH - 1):
l[P] = l[P+1]
LENGTH=LENGTH-1
l[LENGTH]=None
Now try:
print(l) # [92, 50, 82, 73, None]
Note:
LENGTH-1
and LENGTH-2
are changed to LENGTH
and LENGTH-1
because Python uses 0-based indexing.