Python Forum

Full Version: Finding largest value in a for loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The Receiver PC receive multiple TOS value.
I just want to capture the largest value.
why the code below doesn't work.

list
largest=0

for True:
if SourceAddress="1.1.3.8"
var = str(TOS)
print('Type of Service {0}'.format(var))
if(var> largest)
largest = var

print('Max value{0}'.format(largest))
You need to help us in order for us to help you. That starts by properly posting your code. As it is, you have no indentation. When you say "...the code doesn't work", be specific. What doesn't work? If you get an output, what is the output. If you get an error, what is the error.

What is "list" supposed to do?
What is "for True:" supposed to do?
Where are you getting "SourceAddress" from?
Where are you getting "TOS" from?

Comparisons use a double equal sign, not a single one.
if value == another_value:
You declare largest as numeric and var as a string, than try to compare them, this will cause an error.