[Python] I'm asking you a question about a code (for, while, dictionary, input) that outputs the time that all n team members can have a meeting!

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

Hello, I'm Corinne. I've been learning Python for about a month.

The code I want to implement is

If you enter the time of the month and day (n to n) that n people can meet,

I'd like to print out a print (the available date for the meeting is "", x, and "".

Here's the code we've implemented so far.

person_info.py

persons = [ ] #peoplelist
name = [ ] #List of entered names

while True: 
    try:
        personCount = int("Enter the total number of people." : ")) 
    except ValueError:
        print("Only numbers are allowed. Please re-enter it.")
        continue
    else:
        break
whileTrue: #Putting names in the list.
    name = input ("Please enter a name"). : ")
    persons.append(name)
    if len(persons) == personCount:
        break

print("The entered name is", people, "total", personCount, "name.") #peoplelist, total, number of people, and name.

So we've modularized it for n people to use.

The code we implemented next is

person_schedule.py

from person_info import *
from collections import defaultdict

timeDict = defaultdict(list)


while True : 
    number = 0
    inputNum = """
    Enter 1 to continue entering the schedule
    Enter 2 to stop typing the schedule and move on to the next step
    Enter 3 to exit the program
    Enter text : """
    timeDict[persons[0]].append("Enter the month in mm")
    timeDict[persons[0]].append("Enter the day in dd.")
    timeDict[persons[0]].append("Enter the start time as hh.")
    timeDict[persons[0]].append("Enter the end time as hh")
    print(timeDict)
    number = int(input(inputNum))
    if number == 1:
        print("continue")
        continue
    elif number == 2: 
        print("next member")
    elif number == 3:
        print("exit")
        break
    else:
        print("error: Enter an exact number.")

So far, we've done this.

What I want to do is work normally Only person_info.py above.

First, let's make person_schedule.py below Here's what the capital code envisioned.

while True: (The goal is to include their own information in the dictionary from beginning to end)
Iterative sentence start (I want to put multiple values (month and day [start time to end time]) in one key (team member) in all dictionaries)

 0. Prepare to enter into team member timeDict (0) (Repeat until everyone in the list enters) 
from personal[0] to [-1] 

 1. Enter month/day ("mm month/dd day")
 2. Enter the start time to end time (hh number 2)
 3. Enter 1 to continue entering the schedule.
 4. Exit and enter 2 to enter the next member.
 5. Enter 3 to exit the program.

# 1 Input

 1. Enter month/day ("mm month/dd day")
 2. Enter the start time to end time. (Enter hh number 2)
 3. Enter 1 to continue entering the schedule.
 4. Exit and enter 2 to enter the next member.
 5. Enter 3 to exit the program.

# 2 Input
# Next member

 0. Prepare to enter into team member timeDict (1) (Repeat until everyone in the list enters) 

 1. Enter month/day ("mm month/dd day")
 2. Enter the start time to end time (hh number 2)
 3. Enter 1 to continue entering the schedule.
 4. Exit and enter 2 to enter the next member.
 5. Enter 3 to exit the program.

# 1 Input

 1. Enter month/day ("mm month/dd day")
 2. Enter the start time to end time (hh number 2)
 3. Enter 1 to continue entering the schedule.
 4. Exit and enter 2 to enter the next member.
 5. Enter 3 to exit the program.

# 2 Input (Pause of last member If it is not the last, continue until the last member is entered)

# 3 Forced to exit the program upon input.



Sort all the months/days/times

Find a common month/day/time (via True,false) #BrowseIntersectionFunction


Possible month/day/hour output.
The format of meetingTime is mm/dd/hh

print("The available date for the meeting is," meetingTime.")

The reason why I thought like this Since the time available and the number of members may vary, I used the for statement instead of the for statement.

Currently, the most problematic part is when you save it in a dictionary.

{
people(0): [m0 "Month", "/", d0, "Day"]; [h0 "Time", ~, h1, "Time"]; [m1 "Month", "/", d1, "Day"]; [h0 "Time", ~, h1, "Time"];...
individuals(1): [m2 "Month", "/", d2, "Day", h0 "Time", ~, h1, "Time"] , [m3 "Month", "/", d3, "Day"] , h0 "Time", ~, h1, "Time"] , ...
personal(n): [nnn "month", "/", nn "day", nn "time", ~, nn "time", nn "time", nn "month", "/", nn "day", nn "time", ~, nn "time", ...
}

I'd like to save it like this and compare it here, so I'll ask you something I'm curious about.

It must have been hard to read because it was too long, but thank you for reading it.

The reason I'm asking this question is not because I want you to make a full code, but because I'm asking for your advice! I looked it up in GitHub and googled it, but the reality was that it was difficult to search due to lack of experience, and I want to make it myself, but I haven't made any progress here.

I really respect those who do coding.

python

2022-09-20 08:46

1 Answers

Well, I'd do this.

I think 30 to 40 lines would be enough if it was long. (I didn't do it because I was lazy)

Please check the module documentation for datetime.


2022-09-20 08:46

If you have any answers or tips


© 2022 pinfo. All rights reserved.