Bav Bav - 6 months ago 11
Python Question

write input of string in list in python

every time i press enter key shows me

[]
none


i do not know why and i want to write number 6 instead of passing it as a parameter stackoverflow do not accept the question until i write anything but i write all what i know i use pytharm by the way
i want the output something like that

6
baraclona
madrid
spain
africa
USA
UAE


code

def OutputMostPopularDestination( count):
test = input(count)
inputs =[]
for i in test:
string_input = input()
inputs.append(string_input)

print(inputs)

print(OutputMostPopularDestination(6))

Answer

You have a number of problems in your program. Here are some of them:

  • You pass in count, but you use test in your loop
  • input() returns a str, but you use it as an int. A conversion is required.
  • The typical counting for loop is like for i in range(count). A call to range() is required.
  • Functions with no return statement implicitly return None. A return inputs is required.

Try this:

def OutputMostPopularDestination( ):
    test = int(input("How many lines?"))
    inputs =[]
    for i in range(test):
        string_input = input()
        inputs.append(string_input)

    return inputs

print(OutputMostPopularDestination())
Comments