Python Forum
Finding largest value in a for loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding largest value in a for loop
#1
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))
Reply
#2
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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Help to find the largest int number in a file directory SalzmannNicholas 1 1,634 Jan-13-2022, 05:22 PM
Last Post: ndc85430
  find 2 largest equal numbers Frankduc 13 3,549 Jan-11-2022, 07:10 PM
Last Post: Frankduc
  Largest product in a grid (projecteuler problem11) tragical 1 2,292 Sep-14-2020, 01:03 PM
Last Post: Gribouillis
  Extract the largest value from a group without replacement (beginner) preliator 1 2,078 Aug-12-2020, 01:56 PM
Last Post: DPaul
  frequency of largest number group anshumanmuj 5 3,006 Jun-22-2020, 04:51 PM
Last Post: perfringo
  Sort by the largest number of the same results (frequency) inlovewiththedj 3 2,217 Apr-01-2020, 07:29 AM
Last Post: DPaul
  Find the second largest number DarkCraftPlayz 8 11,332 May-29-2019, 02:46 AM
Last Post: heiner55
  Need help for finding cumulative values in a loop Lightning1800 10 6,144 May-23-2018, 07:48 PM
Last Post: Lightning1800
  How to use python to do "for each 365 data, print the largest 18 value? ctliaf 1 2,667 Apr-28-2018, 08:14 PM
Last Post: snippsat
  Calculate the fewest zip codes, for the largest coverage nilamo 4 7,002 Mar-23-2017, 01:31 PM
Last Post: Bass

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020