首页 > 解决方案 > 我正在尝试在 python 中创建密码系统。我不知道这有什么问题

问题描述

import os

pasword = os.environ['PASSWORD']

askpassword = input("Enter Password : ")
if askpassword == (pasword)
    print ("Correct Password, you now have access to this code")
if not askpassword == (pasword)
exit()

这是我的代码,它告诉我这个错误:

  File "main.py", line 6
    if askpassword == 'pasword'
                              ^
SyntaxError: invalid syntax

顺便说一句,我正在使用https://replit.com

标签: pythonsyntax-error

解决方案


简单的修复 - 你忘记了一个冒号。

if askpassword == (pasword):

在 python 中,所有控制结构都需要在它们之后有一个冒号。


推荐阅读