Comparison of the elements of the list of pairs in turn, and output how many times the first number was more than the second, how many times the first number was the second? 3 Number from the list Compare from 4, 5 seconds 6 etc.
I will describe the task, the person decided to run every day, and wants to mean in which day he ran more than in the previous one, it is comparisons that should take turns, and not compare with all days.
My shockode looks like that
lista = []
Day = int (Input ("Run Days:"))
For Day in Range (0, Day):
Km = Float (Input ("km on day:"))
Lista.APPEND (KM)
Print ("You ran", Day + 1, "Days of By", * Lista, "Km.")
IF Lista [0] == Lista [1]:
Print ("There was no improvement")
ELIF Lista [0] & gt; = list [1]:
If you compare the first two elements of the list, I still understand how, how to make it so that if the list was 10 days, he made 5 comparisons? And if 20 then 10! Since each time the sheet consists of a different number of elements …
And also need Python to bring all data type to “print” when was the improvement? And when it was not? And the most important thing important to me is to know how much it was in principle an improvement? (“You have improved your result 3 times” for example)
Task translation from German
“Gunter wants to prepare for the marathon. For this, he runs on Saturdays
• It measures each run. He wants to know how often the current mileage is better than the previous one.
• Gunter calls this “improvement” script.
Create a function that receives a list of mileage kilometers per day as a parameter and outputs how often Günther has a “improvement”. “
Answer 1
Calculate the number of days with a big mileage than in the previous one. Comparisons will be, by the way, 9 for 10 days (n-1)
LargeCNT = 0
For Day in Range (1, Len (Lista)):
IF Lista [Day] & GT; Lista [Day-1]:
LargeCNT + = 1
Print ('days with zoom:', LargeCNT)
You can add
if lista [i] & gt; Lista [I-1]:
LargeCNT + = 1
still do something
ELIF Lista [i] == Lista [I-1]:
same way
ELSE:
worse