LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Python Programme (https://www.linuxquestions.org/questions/linux-newbie-8/python-programme-4175464453/)

Thilinamc 06-02-2013 08:35 AM

Python Programme
 
Hello,

I'm a new member to this forum... So I'm gonna post my first post here...

I have to write a program according to the below description...

"The laughs parking garage contains a single lane that hold up to ten cars. Cars arrive at the south end of the garage and leave from the north end. If a customer arrives to pick up a car that is not northernmost, all the cars to the north of his car are moved out, his car is driven out, and the others cars are restored in the same order that they were in originally. Whenever a car leaves, all the cars to the south are moved forward. So that at all the times all the empty spaces are in the south part of the garage.

Write a python program to reads a group of input lines. Each line contains an “a” arrival or a “d” departure and a license plate number. Cars are assumed to arrive and depart in the order specified by the input. The program should print a message each time that a car arrives or departs. When a car arrives, the massage should specify whether or not there is room for the car in garage. If there is no room for a car, the car waits until there is room or until a departure line is read for the car. When room becomes available, another massage should be printed. When a car departs, the massage should include the number of times the car was moved within the garage (including the departure itself but not the arrival), this number is 0 if the car departs from the waiting line. "

Can anybody please tell me where to start with......It should be done using stacks and queues. If you can submit a code that would be even great

gdejonge 06-02-2013 09:11 AM

Please read the forum rules.
We are happy to help you if you get stuck, but we're not going to do your homework for you.

Cheers.

Thilinamc 06-02-2013 09:51 AM

Quote:

Originally Posted by gdejonge (Post 4964014)
Please read the forum rules.
We are happy to help you if you get stuck, but we're not going to do your homework for you.

Cheers.

Hey,

I'm not asking anyone to do any homework for me.... I'm just asking where to begin with , in coding this in to a program... Hope you understand what I'm trying to do here..

Cheers mate....

archShade 06-02-2013 02:01 PM

This really sounds like you are asking the LQ community to do your homework. You have already worked out that you need to use queues and stacks. A quick google gets you here.

http://docs.python.org/2/tutorial/datastructures.html

You may want to implement a class car with fields UID, arrive, and depart

Also it's worth having a better name, I imagine there 100's of threads in LQ about python.


PS: Don't take this a criticism but there are some quite major English mistakes in your post:
  • It's a computer program (regardless of British or US English).
  • It's message not massage (unless the program is meant to rub your skin to tell you the output).
Like I said not wanting to complain about your English, if you go though my posting history you will probably find much worse. I would not mention it is I had not made earlier points.

johnsfine 06-02-2013 02:20 PM

Quote:

Originally Posted by Thilinamc (Post 4964009)
Can anybody please tell me where to start with......It should be done using stacks and queues. If you can submit a code that would be even great

1) "Where to start": Same as any program:
a) Make sure you understand exactly what the program is supposed to do, including obscure case (see below).
b) Figure out how to divide the big project you have into smaller projects.

2) "It should be done using stacks and queues": The data structure needs in your problem are pretty trivial. I don't happen to know the exact definition or capabilities of available Python data structures, but almost any list-like structure should get the job done (since the scale is too small to care about efficiency).
But why did you say "stacks". A stack is fundamentally LIFO (if you don't know that, look up stacks and LIFO and learn it). If you did know that, what part of the problem looks LIFO to you?

3) "If you can submit a code that would be even great": LQ rules and culture discourage us from doing that for homework and even more so discourage you from asking. Please don't ask that again.

Question about the intended behavior of the program:
With the 10 slots filled and 3 more waiting, a car with 3 in front of it is removed. Does that mean
a) The 3 cars in front cycle around to the 7'th, 8'th and 9'th positions, while one of the 3 waiting fills in as 10'th
or
b) The 3 cars waiting get into 7'th, 8'th and 9'th position, while the previous 1st becomes 10'th and the previously 2'nd and 3'rd are now waiting outside.

I think the problem statement implies (a) not (b) but I'm not sure. I always try to spot and decide the obscure cases before I start to design my data structures. Obscure cases often have a big influence on the correctness of the data structure design.

Quote:

Originally Posted by Thilinamc (Post 4964009)
the massage should include the number of times the car was moved within the garage

If I understand the problem correctly, every time any car departs every car in the garage moves. So the number of moves would be equal to the number of departures after that car first entered the garage, up to and including the time it was the one departing. That feels like a strange request. Strange requests always make me think the person specifying the problem has not communicated what he meant. Probably that is over thinking it. But in the classroom and even more so in real software engineering, the person creating the specification has usually made mistakes. If you have an opportunity to keep the other guy's mistakes from becoming your fault, do so. Sometimes all that takes is asking him a question.

jlinkels 06-02-2013 02:36 PM

Quote:

Originally Posted by Thilinamc (Post 4964024)
Hey,
I'm not asking anyone to do any homework for me.... I'm just asking where to begin with , in coding this in to a program... Hope you understand what I'm trying to do here..
Cheers mate....

Well given the problem description, asking for the code in this phase is more or less like looking at a pile of wood and asking for a saw while you have no idea what you are building.

First step is to analyze the problem. And I mean really drawing a parking space and car on a piece of paper and analyze all possible movements of cars arriving, departing and parking.

Then the next step is to how you want to keep track of positions and movement. What kind of data structures you will be using. How to access that data in case you need to know which cars are waiting, parked or departed. What data will you store? License plate, number of movements, time stamps?

Next, what operation will you do on which data? What happens when a car arrives? Which data will be altered? What happens if a car is moved from the waiting queue to the parking lot? Will data be moved? Will data be flagged? You have to make decisions here whether your setup will be procedure oriented or object oriented.

Only after you have analyzed the problem, defined the data structures, the operations on the data structures and objects if applicable, you are able to look into a programming language and coding.

Immediately after this, or even before, you have to design your test vectors. A certain number of test cases where you go thru the process while you know exactly the each step and state of your process.

Only then you can code and test.

I wonder if they don't teach such an approach anymore.

jlinkels


All times are GMT -5. The time now is 02:29 PM.