所以我已经解决了我的最后一个问题(在你的帮助下),但我想通过使用函数使我的程序运行更顺畅。现在我已经宣布并写好了一切(我认为),但是当我执行我的代码时,它什么也做不了。有什么帮助吗?
应该显示与已经过的时间相匹配的沙漏,最长时间为480秒。
所有' s'在我的代码中正确缩进,以便不是问题。我忘记了这一点。
from graphics import GraphicsWindow
def main():
win = GraphicsWindow(400, 400)
canvas = win.canvas()
canvas.setBackground("white")
mc=makechoice()
while mc==yes or mc==Yes:
canvas.clear()
hourglass()
print(' End of session. ')
def makechoice():
mc = input(' Do you want to make use of the hourglass app?. ')
return mc
def hourglass():
dt = int(input('How much time has passed? (In seconds). '))
if dt==0:
canvas.setOutline("blue")
canvas.setFill("blue")
canvas.drawPolygon(150, 50, 250, 50, 200, 130)
canvas.setFill("white")
canvas.drawPolygon(200, 130, 150, 210, 250, 210)
win.wait()
elif dt==480:
canvas.setOutline("blue")
canvas.setFill("white")
canvas.drawPolygon(150, 50, 250, 50, 200, 130)
canvas.setFill("blue")
canvas.drawPolygon(200, 130, 150, 210, 250, 210)
win.wait()
elif dt>0 and dt<480:
x1 = 150 + ((((250 / 480) * dt) - ((150 / 480) * dt)) / 3.1)
x2 = 250 - ((((250 / 480) * dt) - ((150 / 480) * dt)) / 3.1)
x3=200-(((250/480*dt)-(150/480*dt))/2)
x4=200+(((250/480*dt)-(150/480*dt))/2)
y1=50+(50/480)*dt
y2=210-(80/480*dt)
y3=210
canvas.setOutline("blue")
canvas.setFill("white")
canvas.drawPolygon(150, 50, 250, 50, 200, 130)
canvas.setFill("white")
canvas.drawPolygon(200, 130, 150, 210, 250, 210)
canvas.setFill("blue")
canvas.drawPolygon(x1, y1, x2, y1, 200, 130)
canvas.setFill("blue")
canvas.drawPolygon(200,y2,x3,y3,x4,y3)
win.wait()
elif dt<0 or dt>480:
print(' This choice is invalid. ')