Hi,

I am new at Python..i have been asked to create a code for the following item.

A user needs to input the 'room number' and 'date' to equal a answer.

Room Number: R1, R2, R3, R4, R5

R1 = Dates: 1/01/2000, 01/02/2000, 01/03/2000
R2 = Dates: 01/01/2000, 01/03/2000
R3 = Dates: 0/01/2000, 0/01/2000, 0/01/2000
R4 = Dates: 0/01/2000, 0/01/2000, 0/01/2000
R5 = Dates: 0/01/2000, 0/01/2000

R1 01/01/2000 Library1
R1 01/02/2000 Library2
R1 01/03/2000 Class1

R2 01/01/2000 Library2
R2 01/02/2000 Library1
R2 01/03/2000 Class2

R3 01/02/2000 Library3
R3 01/03/2000 Class3

R4 01/03/200 Class4

R5 01/01/2000 Class4
R5 01/02/2000 Library4

What do you start doing first the Input, Define method first??

Dani AI

Generated

A short, practical plan: decide the exact input format, normalize both fields, then do a direct lookup. As suggested, treat this as Input -> Process -> Output. is right to start by designing what the program should ask and show. And correctly warned about Python 2 input differences — prefer Python 3 or use raw_input on 2.x.

Use a canonical key format for lookups. Normalize the room id (trim and upper-case) and convert the user date into a single ISO format (YYYY-MM-DD) with datetime.strptime. Store data as a dictionary of dictionaries: outer key = room, inner key = normalized date, inner value = event or a list of events. That gives fast, simple lookups and handles multiple events per day if needed.

Example lookup helpers (keeps parsing and lookup separate from I/O):

from datetime import datetime

def normalize(room, date_str):
    room = room.strip().upper()
    for fmt in ('%d/%m/%Y','%m/%d/%Y','%Y-%m-%d'):
        try:
            d = datetime.strptime(date_str.strip(), fmt)
            return room, d.strftime('%Y-%m-%d')
        except ValueError:
            continue
    raise ValueError('date format not recognized')

def find_event(schedule, room_input, date_input):
    room, date_key = normalize(room_input, date_input)
    return schedule.get(room, {}).get(date_key, 'No entry for that room/date')

Quick tips: document the accepted date formats so users know what to type; write small tests for normalize and find_event; use lists inside the inner dict if more than one event can share the same room/date; switch to CSV or a tiny SQLite table when the schedule grows. This keeps the flow simple and follows the Input -> Process -> Output approach already suggested.

Recommended Answers

All 7 Replies

In simple terms:
Input Data --> Process Data --> Output Processed Data

I think on programs like this you need to start by thinking about how it should look to the end user. What do you want the program to ask for and what do you want it to respond with.

Then I like to start by breaking it down into smaller parts. First, I'm just going to collect my input like Vegaseat said up above. So write up some code that collects the input and then just prints it back out. Once you've got that working, then put in some code that processes some of the data. Once you've got that working, then you should have a pretty good idea of what functions you need to define so that you can perform that process on all of the users input.

Do you need more specific help on this assignment? Is there a particular thing that you're not understanding? I think the hardest programs are the ones where you don't know where to start.

Hi,
I i have created the first part to input data:

def results ():
roomnumber = input ("Enter Room Number: ")
date = input (" Enter the Date: ")
print roomnumber + date

i am unsure what to do after this how to start create items for the rooms and dates?

Unsure whether i could use this:

roomnumber = {'L1': '01/01/2000', '01/02/2000' etc

unsure if this makes sense?

Double post, sorry.

Since you are using python 2.x, this won't work. Test this code by entering "R1" and "1/01/2000" and see what happens ( and look at "Is there an easy way to do user input in python?" here http://www.faqts.com/knowledge_base/index.phtml/fid/245 ).

def results ():
    roomnumber = input ("Enter Room Number: ")
    date = input (" Enter the Date: ")
    print roomnumber + date

What about the next part?

I am trying to create the table above i.e if the user inputs R1 and the 01/01/2000 then will bring up the class(1,2,3 etc) or library(1,2,3etc).

Could i use something like:

roomnumber = {'L1': '01/01/2000', '01/02/2000' etc

or do i have to do it differently? I am trying to process the data that is being entered...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.