0

I'm a newbie to python. I want to create a list using user inputs to create a table using inputs. Below is my code. I want to keep variable names.

list1=[]
model = input("Enter vehicle model: ")
passengers = input("How many passengers : ")
while True:
    acstats = input("AC or NON AC- 1.AC  2.Non AC :")
    if (acstats =="1"):
        acstats="AC"
        break
    elif(acstats == "2"):
        acstats="Non AC"
        break
    else:
        print("Enter a valid choice")

size = input("enter size : ")
load = input("enter load : ")
    
list1.extend(model,passengers,acstats,size,load)
print(list1)

here is the log after run the code

Enter vehicle model: 
Car
How many passengers : 
6
AC or NON AC- 1.AC  2.Non AC :
1
enter size : 
15
enter load : 
46
Traceback (most recent call last):
  File "main.py", line 18, in <module>
    list1.extend(model,passengers,size,load)
TypeError: extend() takes exactly one argument (4 given)


** Process exited - Return Code: 1 **
Press Enter to exit terminal
Nave3n
  • 3
  • 2
  • 2
    wrap the arguments to extend with `[]`. Extends accepts a list. – matszwecja Jun 08 '22 at 08:40
  • You'll have to use a class / dict as a structure with named fields to insert into the list. – Luatic Jun 08 '22 at 08:40
  • Does this answer your question? [How do I concatenate two lists in Python?](https://stackoverflow.com/questions/1720421/how-do-i-concatenate-two-lists-in-python) – Tzane Jun 08 '22 at 10:21

1 Answers1

0

Extend only take 1 argument so you need to bundle your variable using a list like this

list1=[]
model = input("Enter vehicle model: ")
passengers = input("How many passengers : ")
while True:
    acstats = input("AC or NON AC- 1.AC  2.Non AC :")
    if (acstats =="1"):
        acstats="AC"
        break
    elif(acstats == "2"):
        acstats="Non AC"
        break
    else:
        print("Enter a valid choice")

size = input("enter size : ")
load = input("enter load : ")
    
list1.extend([model,passengers,acstats,size,load])
print(list1)
Felix Filipi
  • 373
  • 2
  • 12