vendredi 15 novembre 2019

Error Shows up when I press the Enter Key-- How can I ignore the enter key and then keep inputting?

In this code I'm inputting as many integers as I want, and then pressing the enter key twice to end the program and get the Maximum Value of all the integers I just input. However, if my first input is the enter key, an error shows up. How do I fix this error (using while and if)so that the code will ignore it and let me keep inputting numbers? Thank you everyone.

print("Please put in some integers and hit the enter key twice to finish:")
s = input()
first = True
while s != "":          
    lst = s.split()     
    for x in lst:
        if first:       
            maxV = int(x)
            first = False
        else:
            if maxV < int(x):
                maxV = int(x)
    s = input()
print(maxV)

Aucun commentaire:

Enregistrer un commentaire