You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

开发简易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.txt file in the same folder as the script. Add at least two lines with 730 and 1600 (each on their own line).
  • Run the script:
    • Choose 1 to mark your check-in
    • Choose 2 to mark your check-out (this will automatically trigger the difference calculation)
    • Choose 3 to exit the system

3. Customization Tips

  • Log Check-In/Out Times: Uncomment the optional code in the check-in block to save timestamps to a check_records.txt file for record-keeping.
  • Adjust File Format: If your values file uses a different structure (e.g., key-value pairs like morning:730), modify the calculate_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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:47:13