CodeSolved

A comprehensive source of programming questions and exercises

System Timer Timer

Practice Easy 839/ Download 806 Views

Write a program that gets a numeric as a second (s) from the user and after S seconds pass the system

3 Answers

import time
import os
import platform

def shutdown_system(seconds):
    """سیستم را پس از گذشت s ثانیه خاموش می‌کند."""
    print(f"سیستم پس از {seconds} ثانیه خاموش خواهد شد...")
    time.sleep(seconds)  # Looking forward to staying for S second

    # Operating system review and executing the shutdown command
    if platform.system() == "Windows":
        os.system("shutdown /s /t 1")  # Turn off in Windows
    elif platform.system() == "Linux" or platform.system() == "Darwin":
        os.system("shutdown now")  # Off on Linux and Macos
    else:
        print("سیستم عامل پشتیبانی نمی‌شود.")

def main():
    try:
        seconds = int(input("لطفاً تعداد ثانیه‌ها را وارد کنید: "))
        if seconds < 0:
            print("لطفاً عددی مثبت وارد کنید.")
            return
        
        shutdown_system(seconds)
    except ValueError:
        print("لطفاً یک عدد صحیح وارد کنید.")

if __name__ == "__main__":
    main()
Mma123 Download Python

The number of seconds must be received from the user Amirhn


import platform
import time
import os

def shutdown_system(s):
    print(f"please wait for shutdown system secend {s}")
    time.sleep(s)
    if platform.system() == 'Windows':
        os.system("shutdown /s /t 1")

number = int(input("number_secend: "))
shutdown_system(number)
Nima1393 Download Python

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close