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.
You can also consider using an f-string:
print(f"This alarm has gone off {count} times")
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
).
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.