zoukankan      html  css  js  c++  java
  • Python笔记-习题43 基本的面向对象分析和设计

    附加练习

    1.我的代码有个bug,为什么门锁的密码要猜11次而不是10次?

    A:因为在循环体外已经有过一次input-12行,如下:

    11      code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
    12      guess = raw_input("[keypad]> ")
    13      guesses = 0
    14
    15      while guess != code and guesses < 10:
    16       print("BZZZZEDDD!")
    17       guesses += 1
    18       guess = raw_input("[keypad]> ")

    所以如果仅需要用不输入10次的话,则需要更改判断条件,如下:

    11      code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
    12      guess = raw_input("[keypad]> ")
    13      guesses = 0
    14
    15      while guess != code and guesses < 9:
    16       print("BZZZZEDDD!")
    17       guesses += 1
    18       guess = raw_input("[keypad]> ")

     

  • 相关阅读:
    docker部署archery
    System系统类
    多变量的梯度下降
    matlab基础语法
    代价函数
    文件操作
    python集合关系
    python日记(四)字典的常见用法
    python日记(三)常用字符串用法
    python日记(二)购物车程序
  • 原文地址:https://www.cnblogs.com/ohlala/p/11447659.html
Copyright © 2011-2022 走看看