zoukankan      html  css  js  c++  java
  • 因为一个变量命名的关系中断了一个while 循环

    因为一个变量命名的关系中断了一个while 循环,有点意思,什么原因?

    IDE:  Pycharm Community Edition

    一、变量命名为 input , 中断了while 循环,不能循环提示输入:

    def isNum(x):

    if isinstance(x,int):
    return True
    elif isinstance(x,float):
    return True
    elif isinstance(x,complex):
    return True
    else:
    return False

    while True:
    try:
    input = eval(input("please input a data:"))
    except:
    continue
    if isNum(input):
    print('true')
    else:
    print('false')

    输出:
      

    please input a data:abc
    please input a data:1
    true

     

    二、变量命名改为 value ,  有效while 循环能循环提示输入:

    def isNum(x):

    if isinstance(x,int):
    return True
    elif isinstance(x,float):
    return True
    elif isinstance(x,complex):
    return True
    else:
    return False

    while True:
    try:
    value = eval(input("please input a data:"))
    except:
    continue
    if isNum(value):
    print('true')
    else:
    print('false')

    输出:

    please input a data:abc
    please input a data:1
    true
    please input a data:2
    true
    please input a data:

     

  • 相关阅读:
    hdu 1045 Fire Net
    hdu 1044 Collect More Jewels
    hdu 1043 Eight
    hdu 1042 N!
    hdu 1041 Computer Transformation
    hdu 1040 As Easy As A+B
    CI在ngnix的配置
    angularjs表单验证checkbox
    chrome浏览器跨域设置
    angularjs向后台传参,后台收不到数据
  • 原文地址:https://www.cnblogs.com/JercanYu/p/12944637.html
Copyright © 2011-2022 走看看