Python Forum
Print The Length Of The Longest Run in a User Input List
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print The Length Of The Longest Run in a User Input List
#1
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
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
I am attempting the following question [Image: view]

My code is as follows :

https://pastebin.com/LKttKcT4

I will be extremely grateful if I someone could help me out here. Thank you.
Reply
#4
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)
I am trying to help you, really, even if it doesn't always seem that way
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Simulate an answer based on user input [Beginner needs guidance] Bombardini 1 1,257 Nov-12-2022, 03:47 AM
Last Post: deanhystad
Sad Find Longest streak for habits johnconar 3 1,821 Sep-12-2022, 07:13 PM
Last Post: deanhystad
  Removing all strings in a list that are of x length Bruizeh 5 3,088 Aug-27-2021, 03:11 AM
Last Post: naughtyCat
  Input validation for nested dict and sorting list of tuples ranbarr 3 3,841 May-14-2021, 07:14 AM
Last Post: perfringo
Question Recursion and permutations: print all permutations filling a list of length N SantiagoPB 6 3,209 Apr-09-2021, 12:36 PM
Last Post: GOTO10
Bug How to print only vowels from an input? PP9044 8 7,427 Feb-26-2021, 04:02 PM
Last Post: Serafim
  How to print all iterations of min and max for a 2D list alaina 4 2,831 Nov-11-2020, 05:53 AM
Last Post: alaina
  Print user input into triangle djtjhokie 1 2,343 Nov-07-2020, 07:01 PM
Last Post: buran
  Why does this function print empty list? hhydration 1 1,501 Oct-28-2020, 02:03 AM
Last Post: deanhystad
  Changing Directory based on user input paulmerton4pope 13 7,885 Aug-14-2020, 11:48 AM
Last Post: GOTO10

Forum Jump:

User Panel Messages

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