Skip to content

Commit 5e2d33c

Browse files
authored
Bedtime.py
a little update, Now the program won't crash if the user enters a negative number in the hours/minutes/seconds selection.
1 parent 84a8abe commit 5e2d33c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Bedtime.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ def PressButon():
5757
time.sleep(1)
5858
print(yellowLight + 'Numbers only')
5959
PressButon()
60+
if seconds < 0:
61+
time.sleep(1)
62+
print(yellowLight + "You can't turn off the computer in the past!")
63+
PressButon()
64+
continue
6065
minutes = hours = 0
6166
time.sleep(1)
6267
os.system('shutdown -s -t ' + str(seconds))
@@ -78,6 +83,11 @@ def PressButon():
7883
print('Set bedtime in hours (decimal values allowed, e.g. 1.5)')
7984
try:
8085
hours = float(input('Enter hours: '))
86+
if hours < 0:
87+
time.sleep(1)
88+
print(yellowLight + "You can't turn off the computer in the past!")
89+
PressButon()
90+
continue
8191
hours_seconds = int(3600 * hours)
8292
time.sleep(1)
8393
os.system('shutdown -s -t ' + str(hours_seconds) )
@@ -95,6 +105,11 @@ def PressButon():
95105
print('Set bedtime in minutes (decimal values allowed, f.e. 2.5)')
96106
try:
97107
minutes = float(input('Enter minutes: '))
108+
if minutes < 0:
109+
time.sleep(1)
110+
print(yellowLight + "You can't turn off the computer in the past!")
111+
PressButon()
112+
continue
98113
minute_seconds = int(60 * minutes)
99114
time.sleep(1)
100115
os.system('shutdown -s -t ' + str(minute_seconds) )
@@ -180,21 +195,30 @@ def PressButon():
180195
if seconds or minutes or hours:
181196
time.sleep(1)
182197
print(greenLight +'Bedtime was set.')
198+
time.sleep(0.3)
183199
print(yellowLight + 'This is only for this program session')
200+
time.sleep(0.3)
184201
print('If you enabled or disabled bedtime via Windows -', yellowLight + "this is won't show here")
202+
time.sleep(0.3)
185203
print('- Option 6 is just for peace of mind and to verify the successful completion or failure of one of the items.')
204+
time.sleep(0.3)
186205
PressButon()
187206
continue
188207
else:
189208
time.sleep(1)
190209
print(redLight +'Bedtime is not set.')
210+
time.sleep(0.3)
191211
print(yellowLight + 'This is only for this program session')
212+
time.sleep(0.3)
192213
print('If you enabled or disabled bedtime via Windows -', yellowLight + "this is won't show here")
214+
time.sleep(0.3)
193215
print('- Option 6 is just for peace of mind and to verify the successful completion or failure of one of the items.')
216+
time.sleep(0.3)
194217
PressButon()
195218
continue
196219

197220
elif a == 7:
198-
print('Goodbye')
221+
time.sleep(1)
222+
print('Goodbye.')
199223
time.sleep(1)
200224
sys.exit()

0 commit comments

Comments
 (0)