Skip to content
Advertisement

Check if the number is round, if not then round it

I have a little python project. Just for fun. There you can add when you want to shutdown your pc. At the beginning you can choose seconds/minutes/hours, and if you choose minutes than the input number* 60 will be in the “shutdown.exe /s /t …). (It’s only working with round numbers, even than 1.5*60 will be round at the end.) I want to check if the …*60 will be a round number or not. And if it isn’t than round it and run with the round number.
There is the code part what i am talking about:

minutes = input(":")
if minutes >= "1":
    minutes = int(minutes)
    minsec = (minutes*60)
    minsec = str(minsec)
    os.system("shutdown.exe /s /t " + minsec)


You can see the full code here.

(I just started learning python and that’s my first question, sorry if something isn’t understandable.)

Advertisement

Answer

I used eval(), this worked:

minutes = input(":")
if minutes >= "1":
    #Minutes Calculation
    minsec = str(int(eval(minutes) * 60))
    #Shutdown with time
    os.system("shutdown.exe /s /t " + minsec)
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement