I am attempting the following question
QUESTION
My code is as follows :
https://pastebin.com/LKttKcT4
Please help me find the solution or teach me what is wrong with my approach. Thank you
Please, before you post any further, read
https://python-forum.io/misc.php?action=help
I moved your thread to correct sub-forum
Please, post your code here in
python tags. If you get any errors, post the full traceback in error tags.
Also, please use meaningful thread titles that describe your problem. Don't use ALL CAPS in posts or title
I am attempting the following question
My code is as follows :
https://pastebin.com/LKttKcT4
I will be extremely grateful if I someone could help me out here. Thank you.
It would be better if you posted your code on this forum rather than in a link.
I have looked at your code. Please rewrite and use meaningful variable names. It is very hard to follow your intentions when you use cryptic / single-character variable names.
A few observations:
- I am confused by:
if i != length: break
as surely that means loop will only execute once?
- you also initialise i to zero but then use it as the counter in a for loop
range()
starts at zero by default
- you are in danger of index going out of range with the i+1 when you are counting to the last item
- you are incrementing i after the while loop, why? (You don't seem to use it)