这段代码有什么问题? [NEWBIE]

时间:2018-01-13 09:25:08

标签: python

所以我最近刚开始使用python,而且我正在互联网上寻找答案。每当我从不同的线程复制并粘贴以下代码时,它似乎总是起作用:

[ec2-user@ip-xxxxx logstash]$ cat logstash.conf 
input {
  sqs {
    queue => "compute-logs"
    polling_frequency => 5
    region => "ap-southeast-1"
    type => "compute-logs"
  }
}
...
output {
  elasticsearch {
    codec => "json"
    hosts => "https://xxxxx.ap-southeast-1.es.amazonaws.com:443"
    user => "logstash"
    index => "%{name}"
    template => "/usr/share/logstash/config/elasticsearch_template.json"
    template_name => "logstash"
    template_overwrite => true
  }
}
[ec2-user@ip-xxxxx logstash]$ ls
elasticsearch_template.json  logstash.conf  logstash.yml
[ec2-user@ip-xxxxx logstash]$ cat logstash.yml 
http.host: "0.0.0.0"
path.config: /usr/share/logstash/pipeline
xpack.monitoring.elasticsearch.url: http://elasticsearch:9200
xpack.monitoring.elasticsearch.username: logstash_system
xpack.monitoring.elasticsearch.password: changeme
xpack.monitoring.enabled: false
log.level: error

即使我重命名变量等也可以工作,但是当我自己重新输入时,我发现无论我尝试什么,它似乎从未真正起作用。这就是我试过的:

    import os
    import time
    #Must Access this to continue.
    def main():
        while True:
            UserName = input ("Enter Username: ")
            PassWord = input ("Enter Password: ")

            if UserName == 'Bob' and PassWord == 'rainbow123':
                time.sleep(1)
                print ("Login successful!")
                logged()

            else:
                print ("Password did not match!")

    def logged():
        time.sleep(1)
        print ("Welcome to ----")

    main()

所以任何想法我做错了什么?我尝试了几件事,但似乎都没有。据我所知,大多数人都会耸耸肩说这是最简单的事情,我不应该打扰,但我真的很想做到这一点。我想继续将它开发成一个网站克隆人,但只能在登录位之后,但是现在我只希望完成登录位。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

if userName == "igoo" or "igor" or "Igoo" or "Igor" and passWord == "b" or "B"中的begin()行是错误的。

应该是:

if userName in ["igoo", "igor", "Igoo", "Igor"] and passWord.lower() == "b"