1

I am having a problem with debugging my program, the instructor said you only need to turn on or off the lines by using "#" or the comment sign in order for the program works. It is all about simple array in python only. Please help thank you

numbers = [10,20,300,40.5,50]

#random indexing --> O(1) get items if we know the index !!!
print(numbers[4]);

numbers[1] = 'Adam';

print(numbers[1]);

for num in numbers:
    print(num);

for i in range(len(numbers)):
    print(numbers[i]);

print(numbers[:-2]);

#O(N) search running time
maximum = numbers[0];
for num in numbers:
    if num > maximum:
        maximum = num;

print(maximum);

2 Answers 2

1

comment out numbers[1] = 'Adam' so that you can do numerical comparison in the looping part.

Btw you don't need ";" in python

Sign up to request clarification or add additional context in comments.

4 Comments

; is still a legal things in python. I see import ipdb; ipdb.set_trace so often.
you can use ; in python to put multiple statements in the same line. Adding it in the end of statements does nothing, but is not a syntax error either
Wow great! Thank you so much for this
Glad it helped and welcome to stack overflow! Try upvoting an answer if you find that helpful or accept an answer to let more people see it at top.
0

Your program has error when 'Adam' compared with maximum. You must add checking if num not str, or you must add # to line: numbers[1] = 'Adam' to solve this problem

1 Comment

Wow great! Thank you so much for this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.