开发简易Checkin/Checkout系统及文件数值差值判断需求
Got it, let's build this simple check-in/check-out system with the required calculation logic. I'll use Python since it's straightforward for this kind of task—here's a step-by-step implementation:
Simple Daily Check-In/Check-Out System
Core Requirements Recap
- Menu-driven interface with two key options: Checkin (option 1) and Checkout (option 2)
- Calculate the difference between values 730 and 1600 pulled from a file; output the difference if it’s greater than 800
Full Working Implementation
1. Menu Interface & Main Logic
First, we'll create a loop that keeps the system running until the user chooses to exit, with clear menu options:
def display_menu(): print("\n--- Daily Check-In/Check-Out System ---") print("1. Checkin") print("2. Checkout") print("3. Exit") choice = input("Enter your choice (1/2/3): ") return choice def calculate_difference(): try: # Read values from a text file (each value on a separate line) with open("values.txt", "r") as file: values = [int(line.strip()) for line in file if line.strip().isdigit()] # Verify both required values exist in the file if 730 in values and 1600 in values: difference = 1600 - 730 # Calculate positive difference if difference > 800: print(f"📊 Difference between 1600 and 730: {difference}") else: print("❌ Error: File is missing either 730 or 1600.") except FileNotFoundError: print("❌ Error: 'values.txt' not found. Create this file first with the required numbers.") except ValueError: print("❌ Error: File contains non-numeric values. Only integers are allowed.") if __name__ == "__main__": while True: user_choice = display_menu() if user_choice == "1": print("✅ Check-in successful!") # Optional: Add code to log check-in time to a file # from datetime import datetime # with open("check_records.txt", "a") as f: # f.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M')} - Checkin\n") elif user_choice == "2": print("✅ Check-out successful!") calculate_difference() elif user_choice == "3": print("👋 Exiting system. Have a great day!") break else: print("❌ Invalid choice. Please enter 1, 2, or 3.")
2. How to Use
- Create a
values.txtfile in the same folder as the script. Add at least two lines with730and1600(each on their own line). - Run the script:
- Choose
1to mark your check-in - Choose
2to mark your check-out (this will automatically trigger the difference calculation) - Choose
3to exit the system
- Choose
3. Customization Tips
- Log Check-In/Out Times: Uncomment the optional code in the check-in block to save timestamps to a
check_records.txtfile for record-keeping. - Adjust File Format: If your values file uses a different structure (e.g., key-value pairs like
morning:730), modify thecalculate_difference()function to parse the file accordingly. - Enhance Error Handling: Add checks for file permissions or empty files if you need more robust behavior.
内容的提问来源于stack exchange,提问作者peter
相关产品推荐
相关产品推荐

