Reputation: 67
I am trying to write a program that the user can enter in how many hours and minutes they want it to go off then, it take the local time and the hours and minutes and add the two together to produce the time for the program to go off.
when I run the program I get this error:
line 30, in alarm_time alarm_hour = (hour_awake + time.strftime('%H')) TypeError: unsupported operand type(s) for +: 'int' and 'str'
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')
print (time_now)
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 + time.strftime('%H'))
alarm_minutes = (minute_awake + time.strftime('%M'))
print (alarm_hour, alarm_minutes)
hours()
alarm_time()
tick()
Upvotes: 0
Views: 117
Reputation: 1761
The reason is that you set hour_awake
to an int in def hours():
hour_awake = int(input(......
and the time.strftime
function returns a str
(string). You cannot +
an int
and a str
together.
To add the number together, you need to int()
your str
s:
def alarm_time():
alarm_hour = (hour_awake + int(time.strftime('%H')))
alarm_minutes = (minute_awake + int(time.strftime('%M')))
print (alarm_hour, alarm_minutes)
Upvotes: 2