hotel management system

Florian Schweikert kelvan at logic.at
Wed Oct 29 15:12:14 CET 2014


On 28/10/14 07:42, ngangsia akumbo wrote:
> Please can someone look at my code and may be advice and may be help me with some correction. I have been learning python for some time now. This is my first project i wish to write. A hotel management system.
> 
> 
> http://pastebin.com/LMHmuTiC

Beside posting the code inline, it would be easier if you had split the
"employee" part and the part with the classes.

I'm not sure what you want to accomplish with this code, but I picked a
few parts:

> if age >= 18:
>     pass
> 
> else:
>     return age_lim()

using a function just to print a single line is quite overcomplicated.
return the result and handle it on the caller side.
why do you use if/else and just pass first path?

if age<18:
    do_something

do the same thing.

I have to guess what the class part should do.

> class Bar:

why calling a class Bar if you use it like some drink counter?

>     total_cost = 0
>     count = 0

not sure you want to use class variables here, do you want to count
amount of a single type of beer? or everything

>     def set_name(self, name):
>         self.name = name
>         return name

don't use setter if there is 0 logic in the function
also it would be better to set this things in the constructor otherwise
and a setter should not return the name just set

>     def set_count(self):
>         counts = Bar.count =+ 1

not really readable code style, counts variable is unneccessary here

> # still have to adjust this section
> 
>     def set_total_cost(self):                      #I am having some errors #calling this functions
>         total = set_price() * set_count()
>         print "Total cost of drinks: ", total
>         pass

well, it's quite obvious this function crashes, you try to use not
defined functions. you have to use self.function_name to access the methods.
But worse than this you want to use (useless) setter to get values and
print them inside the method instead of returning the value and handle
it outside.
Also this is not even a setter, it does not set anything beside a local
variable.

Maybe it would be best you start over again and make one step after
another. Build one part of code and ensure it works before starting with
more code. And ask specific questions if you stuck somewhere.


-- Florian



More information about the Python-list mailing list