如何在循环结束后输入?

时间:2015-08-17 04:37:01

标签: python python-2.7 while-loop

counter=0
actual_password="hi"
enter_password=''
while enter_password!=actual_password and counter<3:
    enter_password=raw_input("pls enter pass")
    if enter_password==actual_password:
        print "well done"
    else:
        print "try again"
        counter += 1

如何在三次尝试后在循环结束时打印再见?

3 个答案:

答案 0 :(得分:2)

这可能有助于...简单if声明。

counter=0
actual_password="hi"
enter_password=''
while enter_password!=actual_password and counter<3:
    enter_password=raw_input("pls enter pass")
    if enter_password==actual_password:
        print "well done"
    else:
        counter += 1
        if counter == 3:
            print 'bye'
            break
        print "try again"

答案 1 :(得分:1)

检查$response = $api->call( "/".$ad_account_id."/reachestimate", RequestInterface::METHOD_GET, array( 'targeting_spec' => json_encode($targeting), 'currency' => 'USD' ) ); return $response->getContent(); 以决定要打印的内容:

<html lang="en">
    <head>
      <meta charset="utf-8">
      <title>jQuery.getJSON demo</title>
      <style>
      #aside {
        display: none;
      </style>

       <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
      <script>
    $(document).ready(function(){
    $(function() {
      $("#toggle").click(function(e) {
        e.preventDefault();
        $("#aside").slideToggle();
        return false;
      });
    });
    });
    </script>
    </head>
    <body>
      <div class="wrap" id="aside">
            <aside class="left-aside">
                <header class="aside-header">
                    <h1>stuff</h1>
                </header>
            </aside>
        </div>
        <a id="toggle">Sidebar</a>

    </body>
    </html>

答案 2 :(得分:0)

这类问题非常适合使用for循环。这将在三次尝试后打印“再见”,或者如果用户输入正确的密码。

actual_password = "hi"

for tries in range(3):
    enter_password = raw_input("pls enter pass: ")

    if enter_password == actual_password:
        print "well done"
        break
    print "try again"

print "bye"