如何修复Python中的ELIF预期表达误差

发布于 2025-01-24 11:36:51 字数 298 浏览 1 评论 0原文

import win32api,time
while True:
    a = win32api.GetKeyState(0x57)
    if a <0:
     print("w")
    a = win32api.GetKeyState(0x53)
    elif a <0:
    print('s')
    time.sleep(0.1)

我是新手,可以python行elif a&lt; 0给我错误````预期expression''我该怎么做才能使它起作用?谢谢

import win32api,time
while True:
    a = win32api.GetKeyState(0x57)
    if a <0:
     print("w")
    a = win32api.GetKeyState(0x53)
    elif a <0:
    print('s')
    time.sleep(0.1)

im super new to python the line elif a<0 gives me the error ```expected expression`` what do i do to make it work? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静谧幽蓝 2025-01-31 11:36:51

当您使用> 时,结构时,您需要在代码中正确的凹痕,因为这将确定在某个时刻执行的说明:

import win32api, time

while True:
    a = win32api.GetKeyState(0x57)
    if a < 0:
        print("w")
    a = win32api.GetKeyState(0x53)
    if a < 0:
        print('s')
    time.sleep(0.1)

You need a correct indentation in your code when you use if and while structures, because that will determine the instructions that execute in a certain moment:

import win32api, time

while True:
    a = win32api.GetKeyState(0x57)
    if a < 0:
        print("w")
    a = win32api.GetKeyState(0x53)
    if a < 0:
        print('s')
    time.sleep(0.1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文