102k views
5 votes
A restaurant recorded the ages of customers on two separate days. You are going to write a program to find the

maximum age of a customer.
What is the missing line of code?
customerAges = [13, 3, 11, 24, 35, 25, 15, 18, 1]
maximum = customerAges[0]
for item in customerAges:
maximum = item
print("Maximum value:",maximum)

User Eazy
by
5.1k points

1 Answer

0 votes

customerAges = [13, 3, 11, 24, 35, 25, 15, 18, 1]

maximum = customerAges[0]

for item in customerAges:

if(item>=int(maximum)):

maximum=item

else:

continue

print("Maximum value:",maximum)

If you assign the item value to the maximum value without compare them, then you should get the input which is 1. Because in the for loop, the program just putting the item value at current index to the maximum value whether it's equal or greater than the current maximum value. In the end of the loop, maximum variable's value will be 1. (Last index of the list)

User SuperShoot
by
4.2k points