I wrote this code and its suppose to give me the highest number but its printing out three number

Question:
I wrote this code and its suppose to give me the highest number but its printing out three number

numbers = [312, 1434, 68764, 4627, 84, 470, 9047, 98463, 389, 2]
high = numbers[0]
for number in numbers:
	if number > high:
		high = number
		print(f" The highest number is {high}")

Basically it’s printing out a number every time it finds a number higher than the current highest number. So just move the print statement out of the loop like so:

numbers = [312, 1434, 68764, 4627, 84, 470, 9047, 98463, 389, 2]
high = numbers[0]

for number in numbers:
	if number > high:
		high = number

print(f" The highest number is {high}")
4 Likes

oh, thank you so much, you are super awesome

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.