Reputation: 135
So, I know the question is confusing, but hear me out. I'm trying to count how many times my code has run, and I got that, but when I try and implement that into a line of printing code, it tells me it can't print integers. Why?
count = 0
now = datetime.datetime.now()
Current_time = now.strftime("%H:%M")
start = datetime.time(10)
end = datetime.time(11)
while start <= now.time() <= end:
count+=1
print("This alarm has gone off + count + "times")
winsound.PlaySound("C:/Users/gabec/Documents/Audacity/Untitled.wav", winsound.SND_ASYNC)
time.sleep(14) ##The sound is 14 seconds long.
Upvotes: 0
Views: 61
Reputation: 50
Your quotes are incorrect: '"this alarm as gone off" + count + "times"'
also, you need to change count from a int (probably not my problem) by typing 'str(count)'
at the start so, (also, I put int()
at the start just in case it will repeat.)
count = 0
now = datetime.datetime.now()
Current_time = now.strftime("%H:%M")
start = datetime.time(10)
end = datetime.time(11)
while start <= now.time() <= end:
int(count)
count+=1
str(count)
print("This alarm has gone off + count + "times")
winsound.PlaySound("C:/Users/gabec/Documents/Audacity/Untitled.wav", winsound.SND_ASYNC)
time.sleep(14) ##The sound is 14 seconds long.
Upvotes: 0
Reputation: 2907
You can also consider using an f-string:
print(f"This alarm has gone off {count} times")
Upvotes: 1
Reputation: 1068
You're using incorrect syntax. Try changing into this:
print("This alarm has gone off", count, "times")
Even if you include your missing double quote for the string, you cannot add a string ("This alarm...."
) with an integer (count
).
Upvotes: 0