Python Forum
Code not detecting blank string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code not detecting blank string
#1
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
Reply
#2
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.
Reply


Forum Jump:

User Panel Messages

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