[Tutor] double ended queue

Alan Gauld alan.gauld at yahoo.co.uk
Sat Nov 4 19:46:00 EDT 2017


On 04/11/17 20:11, Atux Atux wrote:
> i am new to the area and i am struggling with a small project that i have.

You are on the right path.
When faced with any software project you have to keep breaking it down
till you get to something you can write.

You've made a start, lets see what else needs doing:


1) create a program that runs constantly unless the user presses q to
end it.

Done!

> the program asks the user for a number

Kind of there except its asking for a string not a number.
We need to do some work here.

> and puts the number in a queue, then it prints the queue with the new
> element at the end.

We still need to do this bit

> if the number is with 01,02 then it will be added at the
> left hand side

And this...

> without the 0 at the beginning,

>  otherwise at the right hand
> side. 

> the user can remove an item from the end of the queue by typing r. 

> if the user types '0r' it will be removed from the beginning of the queue.

And all those but lets ignore them for now and just
read a number, put it in the queue, print it out and
keep going till the user hits 'q'

while True:
     if input("\n\n\nType  a number to add it to the queue or q to exit:
") == 'q':
         break

So far so good but you want to do a few things to
the input value so you need to store it in a variable

response = input(....)
if response.lower() == 'q':   # allow user some latitude
   break
number = int(response)  # or do we need float???

Now you can add that to the list(aka quque) and print it.

queue.append(number)
print(queue)

Try putting that all together with your existing code
and see how it looks, then we can tackle the other more
complicated options...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list