1. import platform
  2. import sys
  3. def get_runtime_info():
  4. """Retrieves runtime environment information."""
  5. os_name = platform.system()
  6. os_version = platform.version()
  7. python_version = sys.version
  8. # Handle older Python versions (e.g., Python 2)
  9. if sys.version_info.major == 2:
  10. python_version = sys.version
  11. return {
  12. "os_name": os_name,
  13. "os_version": os_version,
  14. "python_version": python_version,
  15. }
  16. def format_runtime_output(runtime_info):
  17. """Formats the runtime information into a user-friendly string."""
  18. output = "Runtime Environment:\n"
  19. output += f" Operating System: {runtime_info['os_name']} {runtime_info['os_version']}\n"
  20. output += f" Python Version: {runtime_info['python_version']}\n"
  21. return output
  22. if __name__ == "__main__":
  23. runtime_data = get_runtime_info()
  24. formatted_output = format_runtime_output(runtime_data)
  25. print(formatted_output)

Add your comment