首页 > 解决方案 > 无效的语法python 2.7

问题描述

在 Visual Studio 2019 IDE 中以及在 IDE 外运行 .py 文件时,else 语句一直标记为无效语法。我一直看到 else 的无效令牌:但是通过 python 文档查看这似乎是正确的。我正在构建一个系统重启脚本来推动 MDM 解决方案。这只是脚本的非常基本的开始。

import os
import time
import datetime

WorkStatus = input ("We are going to restart this computer now, did you save your work? Y or N")

if workStatus == n: print ('Save your work now restart will occur in 5 minutes')
    # wait 5 minutes
print ("rebooting in 5 minutes")
time.sleep(300)

else:
    os.system ("Shutdown /r /t 10")

标签: python-2.7if-statement

解决方案


import os 
import time 
import datetime 

WorkStatus = input ("We are going to restart this computer now, did you save your work? Y or N") 

if workStatus == n:  
    print ('Save your work now restart will occur in 5 minutes') 
    # wait 5 minutes 
    print ("rebooting in 5 minutes") 
    time.sleep(300) 
else: 
    os.system ("Shutdown /r /t 10") 

推荐阅读