Python Forum
Thread Rating:
  • 3 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Incorrect code
#2
Your return statement is in the wrong place. Remember that indentation matters in Python. return f should be at the same indentation level as the for statement.

Once you fix that, you will get an index error. Your looping variable i is going to go to the last index of d, and then your if statement is going to try to go one beyond that with d[i+1]. Normally I would suggest using enumerate, however since this is in homework you may not have gone over that in class. So would suggest for i in range(len(d) - 1):
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Incorrect code - by janek30 - May-08-2017, 04:07 AM
RE: Incorrect code - by ichabod801 - May-08-2017, 12:09 PM
RE: Incorrect code - by janek30 - May-08-2017, 04:06 PM
RE: Incorrect code - by volcano63 - May-08-2017, 07:44 PM
RE: Incorrect code - by ichabod801 - May-08-2017, 04:19 PM
RE: Incorrect code - by nilamo - May-08-2017, 04:25 PM
RE: Incorrect code - by janek30 - May-08-2017, 04:52 PM
RE: Incorrect code - by nilamo - May-08-2017, 05:24 PM
RE: Incorrect code - by volcano63 - May-08-2017, 07:39 PM
RE: Incorrect code - by nilamo - May-08-2017, 07:43 PM
RE: Incorrect code - by nilamo - May-08-2017, 08:21 PM
RE: Incorrect code - by janek30 - May-09-2017, 10:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting an incorrect average, and not sure why? What's wrong with my code? shirleylam852 8 4,823 Nov-20-2020, 05:32 AM
Last Post: deanhystad
  Return giving incorrect value Calingaladha 5 3,440 Oct-24-2018, 09:53 PM
Last Post: LeSchakal
  Writing incorrect passwords to a file till its correct garth 2 5,010 Feb-10-2017, 11:41 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020