Functionalize exit sequence
This commit is contained in:
parent
19559802d8
commit
c095d1d330
@ -147,6 +147,20 @@ def parse_time_string(timestring):
|
||||
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():
|
||||
print("ib-clearance")
|
||||
print("============")
|
||||
@ -166,13 +180,7 @@ def main():
|
||||
else:
|
||||
print("\nStudent still has lessons, clearance not granted.")
|
||||
|
||||
print("\nPress X key to exit, other key to run again.")
|
||||
key = getch()
|
||||
if isinstance(key, bytes):
|
||||
# msvcrt.getch returns type bytes, decode into str.
|
||||
key = key.decode()
|
||||
if key.upper() == "X":
|
||||
break
|
||||
exit_sequence()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user