0

**Hi, I have written a program and I want to know how I can understand how long it takes for my program to loop when the number goes up. What do you think? **

id1 = -1
id2 = -1
max1 = -1
max2 = -1

n = int(input('Enter your number :'))
if n < 2:
    raise ValueError(' "n" must be greater than 1! ')
for i in range(1, n+1):
    id = int(input("enter your ID: "))
    average = float(input("Enter your average: "))
    if average > max1:
        id2 = id1
        max2 = max1
        max1 = average
        id1 = id
    else:
        if average > max2:
            max2 = average
            id2 = id
    enter code here

print("MAX2 = ", max2, '\t', "ID2 =  ", id2)
  • 4
    Take a look at the *time* module and in particular the *perf_counter* function – DarkKnight Jan 26 '22 at 11:38
  • 1
    This: https://stackoverflow.com/questions/14452145/how-to-measure-time-taken-between-lines-of-code-in-python – Fareed Khan Jan 26 '22 at 11:40
  • Does this answer your question? [Python time measure function](https://stackoverflow.com/questions/5478351/python-time-measure-function) – emilaz Jan 27 '22 at 22:10

0 Answers0