Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
number problem
#11
This code is perfectly working without any error and with required result in Pycharm IDE, PYTHON 3.8
I'm student of medical/dentistry field and started my computer program learning since 3 weeks so i know only python, nothing else in programming.
I took your this thread problem as a just one of python exercise to learn more about python.
I think you made some copy/pasting error, sometimes pasting may distort indentation in code and gives error.
I hope you read code line by line from bottom to top after pasting.
Thank you for your feedback anyways.





(Apr-30-2020, 09:09 AM)Shahmadhur13 Wrote: here is final solution.
I have added few more code line to my previous post to arrive at solution.

sequence = True
all_entered_numbers = [0]
win_list = []
loss_list = []
high_num = 0
low_num = 0
loss = []

while sequence:
    current_num = int(input("enter a number: "))
    if current_num >= 0:
        all_entered_numbers.append(current_num)
        prev_num = all_entered_numbers[-2]
        if current_num > prev_num:
            win_list.append(current_num)
            loss_list.append(0)
            high_num = current_num
            loss.append(0)
        elif current_num < prev_num:
            loss_list.append(current_num)
            win_list.append(0)
            low_num = current_num
            loss.append(high_num - low_num)
        else:
            pass
    else:
        sequence = False

print(f"all entry are : {all_entered_numbers}")
print(f"winning list is : {win_list}")
print(f"losing list is : {loss_list}")
print(f"loss occurence is : {loss}")

all_instances = []  # makes nested list of loss occurence
for i in loss:
    if i == 0:
        all_instances.append([])
    else:
        all_instances[-1].append(i)
loss_instances = list(filter(None, all_instances))  # removing zero values
print(f'loss instance = {loss_instances}')
longest = [len(i) for i in loss_instances]  # to find out longest sequel of loss
most_loss = loss_instances[longest.index(max(longest))][-1]
print(f"Most loss is : {most_loss}")
print(most_loss)
Output:
enter a number: 3 enter a number: 6 enter a number: 36 enter a number: 32 enter a number: 32 enter a number: 121 enter a number: 66 enter a number: 24 enter a number: 22 enter a number: 371 enter a number: 661 enter a number: 6 enter a number: 4 enter a number: 8 enter a number: -1 all entry are : [0, 3, 6, 36, 32, 32, 121, 66, 24, 22, 371, 661, 6, 4, 8] winning list is : [3, 6, 36, 0, 121, 0, 0, 0, 371, 661, 0, 0, 8] losing list is : [0, 0, 0, 32, 0, 66, 24, 22, 0, 0, 6, 4, 0] loss occurence is : [0, 0, 0, 4, 0, 55, 97, 99, 0, 0, 655, 657, 0] loss instance = [[4], [55, 97, 99], [655, 657]] Most loss is : 99 99
you can remove some print function lines to remove extra output. I kept to figure out what is happenning at those lines.
Professional Dentist(32years) fell in love with Python during COVID-19 Lockdown.

"Nothing can stop you from learning new things except your own will"

Reply


Messages In This Thread
number problem - by jk91 - Apr-28-2020, 05:38 PM
RE: number problem - by micseydel - Apr-28-2020, 05:39 PM
RE: number problem - by deanhystad - Apr-28-2020, 06:34 PM
RE: number problem - by perfringo - Apr-29-2020, 05:14 AM
RE: number problem - by Shahmadhur13 - Apr-29-2020, 05:27 AM
RE: number problem - by Shahmadhur13 - Apr-30-2020, 09:09 AM
RE: number problem - by Shahmadhur13 - May-03-2020, 02:33 PM
RE: number problem - by jk91 - May-03-2020, 08:05 AM
RE: number problem - by ndc85430 - May-03-2020, 08:08 AM
RE: number problem - by jk91 - May-03-2020, 09:28 AM
RE: number problem - by ndc85430 - May-03-2020, 01:07 PM
RE: number problem - by deanhystad - May-03-2020, 08:25 PM
RE: number problem - by jk91 - May-07-2020, 05:07 PM
RE: number problem - by ndc85430 - May-08-2020, 07:02 AM
RE: number problem - by jk91 - May-08-2020, 07:14 AM
RE: number problem - by buran - May-08-2020, 07:22 AM
RE: number problem - by ndc85430 - May-08-2020, 07:25 AM
RE: number problem - by jk91 - May-16-2020, 07:52 AM
RE: number problem - by ndc85430 - May-16-2020, 08:37 AM
RE: number problem - by jk91 - May-16-2020, 08:58 AM
RE: number problem - by jk91 - May-30-2020, 09:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with number of rows containing null values PythonSpeaker 3 2,248 Nov-23-2019, 06:53 PM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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