I am trying to write a function in python that takes user input and stores it in a list -
right believe have started off loop correctly reason stops after 2 iterations, , when print list, there no values. know beginner question, having trouble this.
def string(): """grabs user input , stores in list""" vegies = [] choice = none while choice != "q": choice = input("please select vegetable or fruit list or q quit:") vegies = vegies.append(choice)
the problem doing veggies = veggies.append(something). method append not return value, wrong write variable = list.append() once, won't return anything, variable hold none value.
in order use append, use veggies.append(something)
def string(): #although not wrong in terms of syntax, not recommended name function 'string' """grabs user input , stores in list""" vegies = [] choice = none while choice != "q": choice = input("please select vegetable or fruit list or q quit:") vegies.append(choice)
Comments
Post a Comment