Python Forum
Finding largest value in a for loop - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Finding largest value in a for loop (/thread-4435.html)



Finding largest value in a for loop - mingchew - Aug-16-2017

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))


RE: Finding largest value in a for loop - sparkz_alot - Aug-16-2017

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.