gpt4 book ai didi

python - python 中除 time.sleep() 之外的其他创建延迟的方法

转载 作者:行者123 更新时间:2023-12-01 07:18:28 24 4
gpt4 key购买 nike

我在我的卡西欧计算器上做了一些Python操作,遇到了一个小问题,我的计算器使用的Python版本是microPython 1.9.4。我无法使用导入时间,因为此版本中没有时间模块。任何帮助将不胜感激。

编辑:将版本更改为1.9.4

我的代码(time.sleep() 位于底部附近):

import time
barriers = []
playerPosition = [11, 1]
playTime = 0
while playTime <= 0:
line = 6
while line >= 1:
if line > 2:
if playerPosition[1] != line:
print(" ")
else:
currentLine = ""
xPosition = 1
while xPosition < playerPosition[0]:
currentLine = currentLine + " "
xPosition = 1 + xPosition
currentLine = currentLine + "|"
xPosition = 1 + xPosition
while xPosition < 21:
currentLine = currentLine + " "
xPosition = 1 + xPosition
else:
obstructions = []
obstructions.clear()
if playerPosition[1] == line:
obstructions.append(playerPosition[0])
for barrier in barriers:
obstructions.append(barrier)
obstructions.sort()
currentLine = ""
nextObstruction = 0
xPosition = 1
while xPosition <= 21:
try:
if xPosition != obstructions[nextObstruction]:
currentLine = currentLine + " "
else:
currentLine = currentLine + "|"
nextObstruction = 1 + nextObstruction
except:
currentLine = currentLine + " "
xPosition = 1 + xPosition
print(currentLine)
line = line - 1
barrierID = 0
while barrierID < len(barriers):
if barriers[barrierID] > 1:
barriers[barrierID] = barriers[barrierID] - 1
else:
barriers.remove(barrierID)
time.sleep(0.5)
playTime = 1 + playTime

最佳答案

Micropython 不包含 time 模块,但它有一个名为 utime 的模块,它实现了标准 Python time 的较小子集模块,幸运的是包括 sleep

所以,您需要做的是:

  • 导入时间更改为导入utime
  • 并将 time.sleep(0.5) 更改为 utime.sleep(0.5)

您可以在 http://docs.micropython.org/en/v1.9.1/pyboard/library/utime.html 找到 utime 的文档。 .

关于python - python 中除 time.sleep() 之外的其他创建延迟的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57835152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com