Apr-29-2020, 05:27 AM
(This post was last modified: Apr-29-2020, 01:19 PM by Shahmadhur13.)
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}")
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 occurance is : [0, 0, 0, 4, 0, 55, 97, 99, 0, 0, 655, 657, 0]
Process finished with exit code 0
I'm novice still I tried my best to solve your problem partially.As you can see in output the list named "loss occurrence" , you can see longest loss sequence is second one with loss of '99' finally.
It's up to you how you wanna get it displayed.
Sorry if you already know this and I have wasted your time.
Professional Dentist(32years) fell in love with Python during COVID-19 Lockdown.
"Nothing can stop you from learning new things except your own will"
"Nothing can stop you from learning new things except your own will"