import random #generate random num random_num = random.randint (1,100) #store maximum number maxi_num = random_num print ("maxi_num",maxi_num) # record the number of random runs until 99 count = 0 while count != 99: random_num = random.randint(1, 100) count =+ 1 if random_num > maxi_num: maxi_num = random_num print ("the update of maximum number is ",maxi_num) else: pass print ("the total count of random runs" ,count) print ("the final maximum number is", maxi_num)
my last two statements are not printing
Your problem is that you are ending up with an infinite loop. This is because you have written
count =+ 1, which will endlessly assign
count to be equal to +1. If you wanted to use the increment operator, you need to do it the other way around,
count += 1, and now your script should work correctly.
thank you, I didn’t realise that