与学徒招聘代理人联系后,我被赋予任务去给我的时钟编程.我目前有一个工作时钟,但是我仍然不满意,因为必须在程序中实现当前时间才能使其成为可用时钟,而我希望用户能够这样做以使其更加用户友好.
hours = input("Set the amount of hours\n")
minutes = input("Set the amount of minutes\n")
seconds = input("Set the amount of seconds\n")
但是,这会产生错误:
‘TypeError:无法将’int’对象隐式转换为str’
它将按计划的预设时间打开时钟,但是从该时间开始不开始计时.
hours = input("Set the amount of hours\n")
minutes = input("Set the amount of minutes\n")
seconds = input("Set the amount of seconds\n")
#hours=15
#minutes=5
#seconds=0
import time
from turtle import*
setup()
t1 = Turtle()
while True:
t1.clear()
t1.write(str(hours).zfill(2) + ":" + str(minutes).zfill(2) + ":"
+ str(seconds).zfill(2),font=("arial",60,"bold"))
seconds = seconds+1
time.sleep(1)
if seconds == 60:
seconds = 0
minutes = minutes+1
if minutes == 60:
minutes =0
hours = hours+1
if hours ==24:
seconds=0
minutes=0
hours=0
最佳答案
原文链接:https://www.f2er.com/python/533083.html