Member Avatar for Chemist

Hi guys,

I'm trying to write my first little program... I tell python the number of minutes i want it to shutdown/hibernate my computer and it will add that to the current time and perform the necessary action. However I'm really struggling to add the number of minutes to the current time. Can anyone offer me any help?? Here what I got so far... I'm using python 3 RC1 incase your wondering

import time
t = time.strftime('%H:%M')
print ('Current time:', t)
i = input("Minutes till shutdown: ")
print (time.strftime('%H:%M', time.localtime(t + i * 60)))

After t = time.strftime('%H:%M') , t is a string, not a number.

Instead of time.localtime(t + i * 60) you probably want something like time.strftime("%H:%M", time.gmtime(time.time()+i*60)) , possibly corrected for timezone.

>>> time.strftime("%H:%M", time.gmtime(time.time()+i*60))
'22:38'

In addition I think using int(raw_input()) is the best practice!

In addition I think using int(raw_input()) is the best practice!

Python30 has done away with raw_input() and simply uses input() which returns a string. So now you have to use int() to convert the string to an integer.

Test it out with:

i = input("Minutes till shutdown: ")
print(i, type(i))

Just be aware of some of the more radical changes that Python30 brings when you want to use much of the existing sample code. The Python30 installation comes with a file 2to3.py ( in directory .\Python30\Tools\Scripts ) that converts Python2x code to Python3x code.

Could you post the code which shuts down your computer, please?

Thanks! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.