Python Forum

Full Version: Menu Problem.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello guys, the idea of my project is self-explanatory by the menu. It is a menu for a hotel booking system. I am stuck on what to do next? How do I make a list of guests, etc. I need to know how the user of my code can enter people into a data table, can anyone help? ((BEGINNER PYTHON))


I have done this so far:

def menu(): 
 
    print("???????????????") 
    print("??  A: Add new member ??") 
    print("?  B: Book a night.  ??") 
    print("??  C: Redeem points  ??") 
    print("?  D: Show members.  ??") 
    print("??  E: Quit           ??") 
    print("????????????????") 
 
 
    answer =str.lower(input(("Please select an option"))) 
    if answer == "a": 
        print("Okay, lets start") 
 
    elif answer == "b": 
        print("Okay, lets start") 
 
    elif answer == "c": 
        print("Okay, lets start") 
 
    elif answer == "d": 
        print("Okay, lets start") 
 
    elif answer == "e": 
        print("Exited") 
 
    else: 
        print("Invalid") 
 
menu()
((Cheers))
Do you have an actual homework description? It would be very helpful in cases like this.

Do you know how you're supposed to store things? I would expect a dictionary. (In a non-intro course, it might be a database, or using JSON on disk.) Are you supposed to have that menu in a loop?
(Jul-06-2018, 08:39 PM)micseydel Wrote: [ -> ]Do you have an actual homework description? It would be very helpful in cases like this.

Do you know how you're supposed to store things? I would expect a dictionary. (In a non-intro course, it might be a database, or using JSON on disk.) Are you supposed to have that menu in a loop?


Itis for a hotel, to store members, create new bookings, etc. We are using while loops, I would like the simplest way of data storage so it can be displayed easily. Any ideas on nezt steps? We are supposed to use a lot of def functions.
I'd start with show members, which will do basically nothing. Then add member. Then test both against each other. I'd use either a dictionary or a list, depending on what you need (it's incredibly unclear from what you've provided).
(Jul-07-2018, 12:37 AM)micseydel Wrote: [ -> ]I'd start with show members, which will do basically nothing. Then add member. Then test both against each other. I'd use either a dictionary or a list, depending on what you need (it's incredibly unclear from what you've provided).

This is the question. There are no restrictions or guides. This is an exam style question. Can you please help me on how to advance from my current code? I am really stuck, Thanks


The managers of Crawdale Hotel Group have decided to update their customer loyalty
scheme. Customers joining the scheme become silver members. Customers are upgraded
to gold members when they have booked 30 nights’ accommodation and to platinum
once they reach 100 nights.
Silver members receive 2500 loyalty points per night booked, gold members receive
3000 points and platinum members 4000 points. The data is stored as a text file.
The data in this table is provided in the SampleData2017.txt file.
Member ID Surname Year joined Membership
status
Nights
booked
Points
balance
Gri33415 Griffiths 2015 Gold 35 40000
Smi22316 Smith 2016 Silver 3 7500
Mia56213 Miah 2013 Platinum 140 165000
All78915 Allen 2015 Platinum 120 145000
Hug91714 Huggett 2014 Platinum 150 50000
Sel77617 Selby 2017 Gold 40 45000
San55614 Santus 2014 Silver 12 30000
Lee44213 Leewah 2013 Silver 15 37500
The loyalty points can be redeemed for nights at the hotels. A night costs 25000 points.
Requirements
The managers want a computer program to help them operate the scheme efficiently.
The program must allow hotel staff to add new members to the scheme, record nights
booked and points redeemed. It must also update a member’s points balance each time
they book nights or redeem points, upgrade their membership status when appropriate
and allow the number and status of the members to be monitored.
The number of nights in a single booking must be limited to a maximum of 14.
The program must allocate a unique ID to each new member consisting of the first three
letters of their surname, plus a three-digit number, followed by the last two digits of the
current year.
Your task is to analyse these requirements and to design, implement, test and evaluate it
If I were a student in an intro programming course and was given this assignment, this is roughly how I would go about approaching this problem.

1. Write a function that imports the data from some form of database and makes it usable. The prompt states it's stored as a text file, you are going to want to write a function that imports data from text files and stores it in the program to be manipulated. If I were writing this program, I would probably clean up the data some, and have it stored in a pandas data frame. There are a lot of other valid approaches to this, but it's probably what I would have done.

2. Write a different function to be able to write any changes to your dataframe back to your text file. Instead of trying to find out what had been changed, I'd probably just write function the overwrites your the text file with the information in the dataframe.

3. Once I had basic input-output out of the way, I would want to write a function that corresponds to each of your specified menu options.
  • Quit - easy enough, print your termination/logout message and then end the program. If I were designing this program, I would toss the menu into a loop where the "quit" option changes a boolean value that causes the program to terminate, if quit wasn't specified it would automatically loop back to the main menu after a task was completed. That way you don't have to continuously restart the program after completing one task (i.e. adding a new member, updating the number of nights, etc).

  • Show Members - I would have probably divide this into sub-options. Probably, one to print a single person's info based on a name or userID, one to print the entire dataframe (or specific columns within the dataframe I was interested in), and one to print summary stats from the entire dataframe.

  • Add New Member - Reads in data stored in text file, accepts input about the member including their name, checks the current year from somewhere (from user input, the computer's clock, etc), determines current member count from the current year (based on checking the previously assigned unique IDs), assigns a unique ID to the added member, defines them a silver level member, fills in rest of columns with appropriate base information, etc. The calls the output data method from #2 to write changes to my text file.

  • Book Night - Reads in data, asks for input on number of nights booked, checks to make sure that less than 14 nights are booked at once, adds the appropriate number of rewards points based nights booked to their total, checks booked night total and changes their membership status if necessary, writes changes to my text file.

  • Redeem Points - Takes input on number of nights redeemed, calculates and subtracts necessary points from current total, adds appropriate number of nights to total, writes changes to my text file.

Depending on how I wanted things to work, or how bulky the code got, I might break it down further.

After that was all done, I would go through and make sure my code is well formatted, my comments made sense, and made sure my code worked.

Finally, I would re-read the prompt and check my code to make sure I didn't miss any technical specifications asked for to avoid a point deduction.
(Jul-08-2018, 03:26 AM)carpe Wrote: [ -> ]If I were a student in an intro programming course and was given this assignment, this is roughly how I would go about approaching this problem.

1. Write a function that imports the data from some form of database and makes it usable. The prompt states it's stored as a text file, you are going to want to write a function that imports data from text files and stores it in the program to be manipulated. If I were writing this program, I would probably clean up the data some, and have it stored in a pandas data frame. There are a lot of other valid approaches to this, but it's probably what I would have done.

2. Write a different function to be able to write any changes to your dataframe back to your text file. Instead of trying to find out what had been changed, I'd probably just write function the overwrites your the text file with the information in the dataframe.

3. Once I had basic input-output out of the way, I would want to write a function that corresponds to each of your specified menu options.
  • Quit - easy enough, print your termination/logout message and then end the program. If I were designing this program, I would toss the menu into a loop where the "quit" option changes a boolean value that causes the program to terminate, if quit wasn't specified it would automatically loop back to the main menu after a task was completed. That way you don't have to continuously restart the program after completing one task (i.e. adding a new member, updating the number of nights, etc).

  • Show Members - I would have probably divide this into sub-options. Probably, one to print a single person's info based on a name or userID, one to print the entire dataframe (or specific columns within the dataframe I was interested in), and one to print summary stats from the entire dataframe.

  • Add New Member - Reads in data stored in text file, accepts input about the member including their name, checks the current year from somewhere (from user input, the computer's clock, etc), determines current member count from the current year (based on checking the previously assigned unique IDs), assigns a unique ID to the added member, defines them a silver level member, fills in rest of columns with appropriate base information, etc. The calls the output data method from #2 to write changes to my text file.

  • Book Night - Reads in data, asks for input on number of nights booked, checks to make sure that less than 14 nights are booked at once, adds the appropriate number of rewards points based nights booked to their total, checks booked night total and changes their membership status if necessary, writes changes to my text file.

  • Redeem Points - Takes input on number of nights redeemed, calculates and subtracts necessary points from current total, adds appropriate number of nights to total, writes changes to my text file.

Depending on how I wanted things to work, or how bulky the code got, I might break it down further.

After that was all done, I would go through and make sure my code is well formatted, my comments made sense, and made sure my code worked.

Finally, I would re-read the prompt and check my code to make sure I didn't miss any technical specifications asked for to avoid a point deduction.



Could you please give me a rough outline of option 1? To show me what I need to progress to. It would be much appreciated as I have small experience in python.
Quote:Could you please give me a rough outline of option 1? To show me what I need to progress to. It would be much appreciated as I have small experience in python.

Assuming the original text file looks something similar to...

Member ID Surname Year Joined Membership Status Nights Booked Points Balance
Gri33415 Griffiths 2015 Gold 35 40000
Smi22316 Smith 2016 Silver 3 7500
Mia56213 Miah 2013 Platinum 140 165000
...

tThen something like...

import pandas as pd

def read_text():

    data_frame = pd.read_csv("/path/to/relevant/file/textfile.txt", sep=" ", skiprows=[0], header=None)
    data_frame.columns = ["Member ID", "Surname", "Year Joined", "Membership Status", "Nights Booked", "Points Balance"]

    return data_frame
... should get the data loaded in and ready to use.
(Jul-08-2018, 11:07 PM)carpe Wrote: [ -> ]
Quote:Could you please give me a rough outline of option 1? To show me what I need to progress to. It would be much appreciated as I have small experience in python.

Assuming the original text file looks something similar to...

Member ID Surname Year Joined Membership Status Nights Booked Points Balance
Gri33415 Griffiths 2015 Gold 35 40000
Smi22316 Smith 2016 Silver 3 7500
Mia56213 Miah 2013 Platinum 140 165000
...

tThen something like...

import pandas as pd

def read_text():

    data_frame = pd.read_csv("/path/to/relevant/file/textfile.txt", sep=" ", skiprows=[0], header=None)
    data_frame.columns = ["Member ID", "Surname", "Year Joined", "Membership Status", "Nights Booked", "Points Balance"]

    return data_frame
... should get the data loaded in and ready to use.


Thank you! I shall try this now and report back with any issues. This is much appreciated.
(Jul-08-2018, 11:07 PM)carpe Wrote: [ -> ]
Quote:Could you please give me a rough outline of option 1? To show me what I need to progress to. It would be much appreciated as I have small experience in python.

Assuming the original text file looks something similar to...

Member ID Surname Year Joined Membership Status Nights Booked Points Balance
Gri33415 Griffiths 2015 Gold 35 40000
Smi22316 Smith 2016 Silver 3 utopia
Mia56213 Miah 2013 Platinum 140 165000
...

tThen something like...

import pandas as pd

def read_text():

    data_frame = pd.read_csv("/path/to/relevant/file/textfile.txt", sep=" ", skiprows=[0], header=None)
    data_frame.columns = ["Member ID", "Surname", "Year Joined", "Membership Status", "Nights Booked", "Points Balance"]

    return data_frame
... should get the data loaded in and ready to use.



Where do I insert my version of the code you kindly provided in relation to my current code, and also how do I make it so that when the user selects the option to show all the members, this shows up. How do I link it to the relevant option? Cheers.:
    answer =str.lower(input(("Please select an option"))) 
    if answer == "a": 
        print("Okay, lets start") 
  
    elif answer == "b": 
        print("Okay, lets start") 
  
    elif answer == "c": 
        print("Okay, lets start") 
  
    elif answer == "d": 
        print("Okay, lets start") 
  
    elif answer == "e": 
        print("Exited") 
  
    else: 
        print("Invalid") 
  
menu()
Pages: 1 2