newbie for python here.
i'm trying to validate if user input is empty for a nested list to store (x y coordinate). If user did not input anything, codes should be displaying a message e.g. "No input" and will loop back prompting the user to input.
Had been searching everywhere on validate empty nested list, or validate empty input but i just can't put the knowledge together. An example of the code is display below:
add = "y"
xy = []
#-------------------------------------
def count_list(l):
count = 0
for e in l:
if isinstance(e, list):
count = count + 1 + count_list(e)
return count
#--------------------------------------
while (add == "y"):
xy.append([(input("Input x value: ")), (input("Input y value: "))])
add = input("Additional (x, y)? [y/n] ")
qty = (count_list(xy))
print ("(x, y) coordinate(s) inserted:- " + str(xy))
print ("No. of coordinate(s) inserted:- " + str(qty))
Output
Had been cracking my brain for this. Notice 2nd nested list is empty. Am trying to find out how stop the code to proceed but instead prompting the user with a msg "no input". The position of the empty nested list should not be added into the list.
Also have no idea why my count_list function also include counting in an empty nested list. T_T
