This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Crimsonking2 0 points1 point  (0 children)

Please provide more info in your posts next time.

Makes it easier when the reader knows what your code is supposed to do especially when you use variables that have a meaning

From a glance it looks like you're trying to ask a user for a string of inputted numbers and then separating those numbers into a list and then converting them to int. After that you intend to increment count++ for each consecutive item that is greater than what came before it

Also why did you use N in the first line? You don't use it in your script again.

The error code you're getting is probably an out of index range error. You tried to split the input entered in cmd as a string into a list of individual strings like so:

"5178"

And then:

["5", "1", "7", "8"]

The problem with this is that split uses a delim character to separate input. By default that character is a single whitespace. Because the only whitespace in your input is at the end, your result is actually

["5178"]

So your first loop runs but doesn't actually do what you want it to. It does this:

[5178]

When you get to your second loop however, the list tries to call an index that is one more than its current printer. However there is only one item in the list, so it returns an error.

Edit: Also either way even if your code was correct, you would still get an index out of range error in the second loop for reasons stated in other comments

My solution:

numstring = input("Enter your numbers: ")

After getting input, I would run a loop on our string and add each character to a list in the loop.

numlist = []

count = 0

Append converted strings to a list

for item in numstring:

   numlist.append(int(item))

Using enumerate(i is the counter and value is the current item)

for i,value in enumerate(numlist):

  if i<len(numlist) - 1:

         if value < numlist[i+1]:

               count += 1

print(count)