1
print("Please enter integers (then press enter key twice to show you're done):")
s = input()                  #whatever you're inputting after the print
first = True                 #What does this mean???
while s != "":               #What does this mean???
    lst = s.split()          #split all your inputs into a list
    for x in lst:
        if first:                            #If its in ur lst?
            maxV = int(x)           #then the max value will be that input as an integer
            first = False                #What does this mean?
        else:
            if maxV < int(x):
                maxV = int(x)
    s= input()
print(maxV)

I'm confused as to what first=True and first= False in this code, what does it mean to set a variable equal to true or false? Also confused as to what while s != "": means. Sorry, I'm a complete beginner, would be forever grateful if someone could help me

luigigi
  • 4,146
  • 1
  • 13
  • 30
Diana A
  • 11
  • 1
  • 2
    what language is this supposed to be? it sure isn't Java, so why did you tag it as Java? – Stultuske Nov 13 '19 at 07:04
  • 1
    These are very basic questions and there is a place where those questions get answered: the [Python Tutorial](https://docs.python.org/3/tutorial/index.html) – Matthias Nov 13 '19 at 07:08
  • This looks like python so I'd hazard a guess you want to know about the Syntax of the if statements with Booleans : https://stackoverflow.com/questions/38423360/syntax-for-an-if-statement-using-a-boolean – lloyd Nov 13 '19 at 07:10

2 Answers2

1

I don't really know what programming language this is but with basic knowledge I can kinda tell you what these things mean. I hope it helps:

print("Please enter integers (then press enter key twice to show you're done):")
s = input()                  #Here s becomes your input
first = True                 #Here you set first as a boolean which can have the state true or false. In this example it gets the value True assigned
while s != "":               #While repeats a certain process and in this example it keeps this process going while s isn't empty
    lst = s.split()          #splits all your inputs into a list <- you got that right
    for x in lst:
        if first:                        #It checks if first is true. If it is true it keeps going with the code right after the if
            maxV = int(x)                #then the max value will be that input as an integer
            first = False                #this sets a new value to first. which is false in this case
        else:
            if maxV < int(x):
                maxV = int(x)
    s= input()
print(maxV)

Additionally you said you didn't understand the !=. != is like == but the opposite. It means unequal. Therefore if you say something like 1 == 1 this is true, because 1 equals 1. If you say 1 != 2 this is true because 1 is not the same as 2.

THess
  • 1,003
  • 1
  • 13
  • 21
  • This is really helpful, thank you soooo much. Although I'm still kind of confused about lines 6 and 7. You're checking if x in list (if my different inputs) are first (are true or false). How can integers (lets say I input 3, 4, 47, 62, etc) can be true or false? I understand that the for function is a loop, so it's going through every single input (x in lst) -- and checking IF it's "first" or not. What exactly does it mean if my integer is "first", what does it mean for my x's in lst to be either "true" or "false"? – Diana A Nov 13 '19 at 07:23
  • Sorry if this is confusing! – Diana A Nov 13 '19 at 07:27
  • Or is it just automatically "first" (aka true) because you set it before in first=true, and it just stops being the case once you set first=false? – Diana A Nov 13 '19 at 07:28
  • @DianaA `for x in lst` is what you call a for loop. It goes through the code below and counts 1 up for every loop until `x` reaches the value of the size of the list after the `in`. For example, if I say `for x in range(0,5)` the code below gets executed 5 times. Hope this helps. – THess Nov 13 '19 at 07:28
  • `First` doesn't have to do anything with the integers in the list. `First` is just a boolean that is there to check if it's the first time the loop is executed. If it **is** the first time executed, `maxV` gets set to the first number of the list. Then `first` gets set to false so this part never gets executed again. – THess Nov 13 '19 at 07:31
  • 1
    @THess " It goes through the code below and counts 1 up for every loop until x reaches the value of the size of the list after the in." It does not. It goes through every *value* in the list object, not 0 -> len(list_object). Python for-loops are like iterator-based Java for-each loops. – juanpa.arrivillaga Nov 13 '19 at 07:57
0
first = True                 

set boolean variabel to True

while s != "":

check if input is empty. != means not equal and is the opposite to == which means equal

if first:

if the first variable is True run the code for the if statement. In this case set the value as your max value and

first = False

set first to False since the next value isn't the first value anymore

luigigi
  • 4,146
  • 1
  • 13
  • 30