[Tutor] double ended queue
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
> 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
> without the 0 at the beginning,
> otherwise at the right hand
> 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'
if input("\n\n\nType a number to add it to the queue or q to exit:
") == 'q':
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
number = int(response) # or do we need float???
Now you can add that to the list(aka quque) and print it.
Try putting that all together with your existing code
and see how it looks, then we can tackle the other more
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor