Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79824 > unrolled thread

hotel management system

Started byngangsia akumbo <ngangsia@gmail.com>
First post2014-10-27 23:42 -0700
Last post2014-10-29 15:12 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  hotel management system ngangsia akumbo <ngangsia@gmail.com> - 2014-10-27 23:42 -0700
    Re: hotel management system Chris Angelico <rosuav@gmail.com> - 2014-10-28 18:09 +1100
    Re: hotel management system Florian Schweikert <kelvan@logic.at> - 2014-10-29 15:12 +0100

#79824 — hotel management system

Fromngangsia akumbo <ngangsia@gmail.com>
Date2014-10-27 23:42 -0700
Subjecthotel management system
Message-ID<3f10c652-9d9d-4353-b24f-939d21978998@googlegroups.com>
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

Thnaks

[toc] | [next] | [standalone]


#79825

FromChris Angelico <rosuav@gmail.com>
Date2014-10-28 18:09 +1100
Message-ID<mailman.15253.1414480185.18130.python-list@python.org>
In reply to#79824
On Tue, Oct 28, 2014 at 5:42 PM, ngangsia akumbo <ngangsia@gmail.com> 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
>

Sure, we can do code reviews! It's usually helpful to provide your
code in-line, though, rather than linking to pastebin.

You're using Python 2, as evidenced by the print statements. So don't
do this, ever:

> def emp_age():
>     """displaying employees age"""
>
>     age = input("Enter age: ")

The input function is extremely dangerous. Everywhere else, you use
raw_input, which is correct.

> class Bar:

This is an old-style class. It's better to explicitly subclass object:

class Bar(object):

> class Beer(Bar):

Not sure why you're doing this. Firstly, you never use your Beer
class... but secondly, your Beer isn't a special type of Bar, it's a
quite different thing. When you subclass, it's usually helpful to
follow the Liskov Substitution Principle:

https://en.wikipedia.org/wiki/Liskov_substitution_principle

Think carefully about your class hierarchy, because it defines all
sorts of things about your code. Be sure you're happy with it before
you code up too much else.

ChrisA

[toc] | [prev] | [next] | [standalone]


#79914

FromFlorian Schweikert <kelvan@logic.at>
Date2014-10-29 15:12 +0100
Message-ID<mailman.15300.1414592507.18130.python-list@python.org>
In reply to#79824
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web