-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSchedule.py
145 lines (121 loc) · 4.28 KB
/
Schedule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#Final Project : Barber Shop Appoinmnet system
#Import calendar & datetime to implement in code
import calendar
import datetime
#Display 2021 Calendar
print(calendar.calendar(2021))
#List to hold concatenated string of date and name of appointments
app_created=[]
#List to hold date and time of scheduled apppointment
appointments =[]
#List of names that concatenate with date and time list
names = []
#function to check date is taken or not
def check_date(date1):
if date1 in appointments:
print('Error date already taken\n')
else:
appointments.append(date1)
print('Date entered!!\n')
#Function to check name entered with appointment concatenating with date and time
def search(f_name):
if f_name in names:
print(f_name)
n = names.index(f_name)
print('Appointment on '+ str(appointments[n])+('\n'))
else:
print('No Appointment for given date\n')
#Checks if name containing only letters
def name():
name = input('Enter First name:')
if name.isalpha():
print('Name entered is Valid\n')
names.append(name)
search(name)
else:
print('Invalid name\n')
#prints full appointment scheduled
def print_app():
for i in names:
for j in appointments:
print(i + ' Appointment on '+ str(j))
#Concatenates both list and adds to app_created list
def add_app():
for i in names:
for j in appointments:
newapp =(str(i) + ' Appointment on '+ str(j))
app_created.append(newapp)
#main function displays menu
def main():
#list of available times for the shop
times = ['1pm','2pm','3pm','4pm']
#Prints out menu asks for user input
print('Welcome to the Cutz!!')
print('Would you like to make an Apppointment or look up Appoinment?\n')
print('1. Create Appointment')
print('2. Look up Appointment')
print('3. Quit\n')
#User input for their choice
choice = int(input('Choose 1, 2, or 3\n'))
while choice <=3 and choice>=1:
if choice ==1:
print('\nEnter date for appointment using only numbers\n')
#Assigns year to only 2021
year = 2021
#while loop to allow input and check for date validation
while True:
try:
month = int(input('Enter a month: '))
day = int(input('Enter a day: '))
dt=datetime.datetime(year,month,day)
except ValueError:
print('Invalid Date')
continue
else:
break
#loops through times list
for i in times:
print('\n'+i)
#validates through the valid input for time
while True:
try:
time =int(input('\nEnter time in range 1-4: '))
except ValueError:
print('Not a number')
continue
else:
if 1 <= time <5:
break
else:
print('Out of range. try Again')
#converts time int into str
convt_num = str(time)
tm=datetime.time(time)
#conbimes date and time
combined = dt.combine(dt,tm)
#checks date through function
check_date(combined)
#calls functions
name()
add_app()
choice = int(input('\nChoose 1, 2, or 3\n'))
elif choice == 2 :
f_name = input('\nEnter your first name: ')
#calls function and prints appointment if name match
search(f_name)
choice = int(input('Choose 1, 2, or 3\n'))
else:
for i in app_created:
print(i)
print('Thank you')
break
#calls main function
main()
#Opens file
file = open('Sche_appointments.txt','w')
#While file opens app_created list is written in file
with open('Sche_appointments.txt','w')as out_file:
for i in range(len(app_created)):
print(str(app_created[i]))
#closes file
file.close()