-2

Working on a list creator to generate assignments for a sound crew. Creating 4 lists and adding people to the various lists based on the training they have recieved and the jobs they are capable of doing. I have one base list with all of the people included. The .append works for that list, but for all lists with conditions the names are not appending.

I tried changing my for from for str in addto to other things but nothing has worked so far.

my_list = []
stage_list = []
mic_list = []
all_list = []

def addto_list():
    addto = input()
    for str in addto:
        input("Can he do stage?(y/n): ")
        if input == "y":
            stage_list.append(addto)
        else:
            break
    for str in addto:
        input("Can he do mic?(y/n): ")
        if input == "y":
            mic_list.append(addto)
        else:
            break
    for str in addto:
        input("Can he do sound?(y/n): ")
        if input == "y":
            all_list.append(addto)
        else:
            break     

    my_list.append(addto)

The results I want are when I answer y for any of the conditional statements then the name append to the list. But when I do that the list still appears blank. For example I run the code

addto_list()
Input: Jack
Can he do stage: y
can he do mic: y
can he do sound: y

print(my_list)
return: Jack
print(mic_list)
return: [] blank when it should say Jack
  • Why do you have a for loop ? `for str in addto:` – Devesh Kumar Singh Jul 11 '19 at 04:51
  • 1
    `input` is the function name that you are calling, and thus it will never be equal to `"y"` (when evaluating `input == "y"`), thus it never gets added. – metatoaster Jul 11 '19 at 04:51
  • Also the return value of `input` should be assigned to a variable for it to be used, and don't use `input` as a variable name, something like `flag = input("Can he do stage?(y/n): ") if flag == "y":` – Devesh Kumar Singh Jul 11 '19 at 04:52
  • You call `input()` which returns the inputted string, but you don't put it in a variable so it gets discarded. Then you compare the `input` function to `"y"`. Also, why is there a for loop? You don't want to ask the user multiple times. – eesiraed Jul 11 '19 at 04:53

3 Answers3

1

You need to make the inputs one-line:

my_list = []
stage_list = []
mic_list = []
all_list = []

def addto_list():
    addto = input()
    for str in addto:
        if input("Can he do stage?(y/n): ") == "y":
            stage_list.append(addto)
        else:
            break
    for str in addto:
        if input("Can he do mic?(y/n): ") == "y":
            mic_list.append(addto)
        else:
            break
    for str in addto:
        if input("Can he do sound?(y/n): ") == "y":
            all_list.append(addto)
        else:
            break     

    my_list.append(addto)

Your code didn't work because you input, but then you lose the object since you're not assigning the variable and not using it anywhere, OTOH input is a keyword, that which is <built-in function input>, so it's definitely not "y".

U13-Forward
  • 69,221
  • 14
  • 89
  • 114
0

Try assigning the y/n to an variable instead of using input directly. Like

Stage = input("Can he do stage?(y/n): ") if Stage == "y":

0

Try this method. input shouldn't be used as a variable. And, the for loops are not needed. In this case, it will take each letter(J A C K) and ask for the stage, mic and sound.

my_list = []
stage_list = []
mic_list = []
all_list = []

def addto_list():
    global stage_list, my_list, mic_list, all_list
    addto = input()
    print("Addto", addto)
    choice = input("Can he do stage?(y/n): ")
    if choice == "y":
        stage_list.append(addto)
    choice = input("Can he do mic?(y/n): ")
    if choice == "y":
        mic_list.append(addto)
    choice = input("Can he do sound?(y/n): ")
    if choice == "y":
        all_list.append(addto)
    my_list.append(addto)
Vinu Chandran
  • 305
  • 2
  • 10