Functionalize exit sequence

This commit is contained in:
Abdulkadir Furkan Şanlı 2019-01-17 17:19:22 +01:00
parent 19559802d8
commit c095d1d330
No known key found for this signature in database
GPG Key ID: 7823BD18E6F95D73

View File

@ -147,6 +147,20 @@ def parse_time_string(timestring):
return structtime return structtime
def exit_sequence():
"""Initiate exit sequence.
Asks user to enter character, and exits program if X is pressed.
"""
print("\nPress X to exit.")
key = getch()
if isinstance(key, bytes):
# msvcrt.getch returns type bytes, decode into str.
key = key.decode()
if key.upper() == "X":
exit()
def main(): def main():
print("ib-clearance") print("ib-clearance")
print("============") print("============")
@ -166,13 +180,7 @@ def main():
else: else:
print("\nStudent still has lessons, clearance not granted.") print("\nStudent still has lessons, clearance not granted.")
print("\nPress X key to exit, other key to run again.") exit_sequence()
key = getch()
if isinstance(key, bytes):
# msvcrt.getch returns type bytes, decode into str.
key = key.decode()
if key.upper() == "X":
break
if __name__ == "__main__": if __name__ == "__main__":