我正在尝试编写一个程序,用户可以输入他们希望它关闭的小时和分钟,然后,它需要当地时间以及小时和分钟,然后将两者加在一起以产生程序运行的时间离开。
注意:我不希望它将我的输入和当前时间的数字作为字符串放在一起。我需要它来将数字加在一起。
当我运行该程序时,我收到此错误:
line 30, in alarm_time
alarm_hour = (hour_awake + time.strftime('%H'))
TypeError: unsupported operand type(s) for +: 'int' and 'str'
My Code:
from tkinter import *
import tkinter
import time
time_now = ''
hour = time.strftime("%H")
minute = time.strftime("%M")
str(hour)
str(minute)
def tick():
global time_now
time_now = time.strftime("%H:%M:%S")
def hours():
global hour_awake
hour_awake = str(input("please enter in how many hours you would like to have the alarm go off in. "))
minutes()
def minutes():
global minute_awake
minute_awake = str(input("please enter in how many minutes you would like to have the alarm go off in. "))
def alarm_time():
alarm_hour = (hour_awake + hour)
alarm_minutes = (minute_awake + minute)
print (alarm_hour, alarm_minutes)
tick()
hours()
alarm_time()
如果我正确理解了你的问题,那么尝试将你的 str() 更改为 int() ,如下所示:
from tkinter import *
import tkinter
import time
time_now = ''
hour = time.strftime("%H")
minute = time.strftime("%M")
int(hour)
int(minute)
def tick():
global time_now
time_now = time.strftime("%H:%M:%S")
def hours():
global hour_awake
hour_awake = int(input("please enter in how many hours you would like to have the alarm go off in. "))
minutes()
def minutes():
global minute_awake
minute_awake = int(input("please enter in how many minutes you would like to have the alarm go off in. "))
def alarm_time():
alarm_hour = (hour_awake + hour)
alarm_minutes = (minute_awake + minute)
print (alarm_hour, alarm_minutes)
tick()
hours()
alarm_time()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)