Python Forum
Code not detecting blank string - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Code not detecting blank string (/thread-17000.html)



Code not detecting blank string - SpookyHjke - Mar-24-2019

Hi all,

I am having some issues trying to get my code to detect that there is a blank string(so nothing has been entered)that has been entered in by the user. I am not sure if i am using the wrong function or what is going on.

The question that i am trying to complete is "Write a program that prompts for and reads strings until an empty string is entered,then prints the longest string that was entered. The output must match the punctuation exactly (including quote marks)."
My Code:
time = 1
user_inputs = []

while time > 0:
    user_inputs.append(input("Enter a number"))
    if (user_inputs == ""):
        print("User_Input is empty") #this is here for testing purposes to make sure the code actually works.
        time = 0

print(max(user_inputs))
Some help would be appreciated.
Thanks in advance! Smile


RE: Code not detecting blank string - Yoriz - Mar-24-2019

user_inputs is a list containing inputs, you are checking if the variable is an empty string not the part of the list that was just appended to.