- 5
Write a program to take an input, add it to the end of the queue and output the resulting list.
You are working on a queue management program. The queue is represented by a list. Note: The append() method can be used to add new items to the list. Program: queue = ["John", "James", "Amy"] txt = input() #your code goes here L= queue.append(txt)?
19 odpowiedzi
+ 7
queue = ["John", "James", "Amy"]
txt = input()
queue.append(txt)
print(queue)
Enjoy!
+ 7
Shree Harini
Attempts please?
Check Notes: given in practice
+ 7
Check lesson again and know how to add new data in list. Check examples given in lesson. If you still didn't get then take help from Google..
+ 5
Shree Harini
Why don't you try solving the simple stuff and attempt the difficult stuff after you have developed your skills a bit morr
+ 4
Hey Shree Harini please try solving that if you haven't. And after solving, post your code here. And then if you have problem then ask it here. Thanks
+ 3
I'm a beginner. Thought of giving a try to solve a problem! But, I'm unable to solve it
+ 3
Hi Shree!
You look pretty close!
But, the thing is that you have to recall your knowledge about list functions. I can give you a small example to understand the function of append().
Let's say we have a list named, x.
x = [1,2,3].
If you want to add an element(4) at the end of the list x, this is the way you have to follow.
x.append(4)
Finally, you can print your updated list by using print statement as always.
print(x)
Output: [1,2,3,4]
+ 3
queue = ['John', 'Amy', 'Bob', 'Adam']
txt = input()
queue.append(txt)
print(queue)
+ 2
+ 1
чтобы понять команду .append(), при решении этой задачи необходимо вспомнить что мы уже знаем о списках.
Пример,
Допустим, у нас есть список с именем x.
х = [1,2,3].
Если мы хотим добавить еще один элемент ( например цифру "4") в конец этого списка (списка х = [1,2,3]), мы должны сделать следующее:
х.append(4) и наш код станет выглядеть так:
x = [1,2,3]
х.append(4)
теперь добавим команду вывода на экран (print(x)) и получим уже обновленный (дополненный новым элементом в конце списка) список
x = [1,2,3]
х.append(4)
print(x)
получим:
1,2,3,4
+ 1
Queue = ['India','USA','China']
Now ,if you want to add one more country in this queue - you should use function called -append().
So, just get input from user like,
txt=input()
x=queue.append(txt)
print(x)
😊
+ 1
queue = ['John', 'Amy', 'Bob', 'Adam']
name=input()
queue.append(name)
print(queue)
0
my solution is:
queue = ["John", "James", "Amy"]
txt = input()
queue.append(txt)
print(queue)
0
queue = ['John', 'Amy', 'Bob', 'Adam']
txt = input()
queue.append(txt)
print(queue)
DONE...!
0
queue = ['John', 'Amy', 'Bob', 'Adam']
name = input()
queue.append(name)
print(queue)
0
queue = ['John', 'Amy', 'Bob', 'Adam']
txt = input()
queue.append(txt)
print(queue)
0
Question: You are working on a queue management program. The queue is represented by a list. Write a program to take an input, add it to the end of the queue, and output the resulting list.
Answer:
queue = ['John', 'Amy', 'Bob', 'Adam']
item = input()
queue.insert(4, item)
print(queue)
OR
queue = ['John', 'Amy', 'Bob', 'Adam']
item = input()
queue.append(item)
print(queue)
0
txt = input()
queue.append(txt)
print(queue)
0
queue = ['John', 'Amy', 'Bob', 'Adam']
name = input()
queue.append(name)
print(queue)