#πŸ”’ i cant understand

13 messages Β· Page 1 of 1 (latest)

midnight crescent
#

For students living off-campus (we have used IP TA names for this), suppose records of whenever a student enters or exits the campus are maintained in a data file. A typical data entry will look like this: "Student_Name, Crossing (can be ENTER or EXIT), Gate-number, Time (in 24 hr format)”
If, in the record, a student is shown to enter even if he had previously entered the campus, i.e., two ENTER entries before EXIT, take the first one. Similarly, there can be two consecutive EXIT entries from the campus for a student - if so, take the last one. You are given the data for one day (A sample data file can be downloaded from File). If for a student there is EXIT but there is no ENTRY - it means he/she came the day before; similarly if ENTRY but no EXIT, it means that the student will leave next day.
Convert this data into a nested dictionary. The keys should be the name and value should be another dictionary containing a list of gate no, crossing type, time. Use this dictionary to answer the following queries (for querying, you can write a small loop and ask for a number between 1 and 3 - if no input given, then end).
Given a student name (as input), show the record of students moving in/out of campus (as a list of tuples) in the day (in an output text file), and whether currently present in campus or not. Take another input for current time as well.
Given the start time and the end time (in 24hr format, both inclusive) as input, determine all the students who entered the campus during this, and all students who exited the campus during this time. Save the result into an output text file, with the format similar as the input data file.
Given the gate number (as input), determine the number of times students have entered the campus through that gate, and the number of times students have exited the campus from that gate.

vernal vigilBOT
#

@midnight crescent

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

brazen pebble
#

What parts are unclear?

midnight crescent
brazen pebble
#

Read the data file (looks like a CSV file, see the csv module).
Make a dictionary from the data from the file.
Write a loop to prompt for the type of query (they suggest maybe a number from 1-3) and then the query itself (eg a student name for type 1, and so on).
Look up what's asked for and print out the answers.

#

!doc csv

vernal vigilBOT
#
csv

Source code: Lib/csv.py

The so-called CSV (Comma Separated Values) format is the most common import and export format for spreadsheets and databases. CSV format was used for many years prior to attempts to describe the format in a standardized way in RFC 4180. The lack of a well-defined standard means that subtle differences often exist in the data produced and consumed by different applications. These differences can make it annoying to process CSV files from multiple sources. Still, while the delimiters and quoting characters vary, the overall format is similar enough that it is possible to write a single module which can efficiently manipulate such data, hiding the details of reading and writing the data from the programmer.

midnight crescent
#

should i make a tuples inside the nested dictionary

#

Given a student name (as input), show the record of students moving in/out of campus (as a list of tuples)
list of tuples inside a nested dictionary ?

brazen pebble
#

They say it should be a nested dictionary, but that seems odd to me. From what they write ("value should be another dictionary containing a list of gate no, crossing type, time") really sounds like a list, with a tuple for each crossing record. eg (gate,crossing,time) (or a 3 element list, either would be fine). So something looking like:

{ "student_a": [
    (1,"ENTER","9:05"),
    (1,"EXIT","12:05"),
  ],
  "student_b": [
    ... more records ...
  ],
}
#

... which is just a dict mapping student->list

vernal vigilBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.