python - 需要帮助创建具有两个参数的输入函数

标签 python python-2.7

我已经编码了大约一个月,我刚刚开始研究函数。 该函数将提示用户输入一个整数。如果数字低于low或高于high,则会向用户输出一条错误消息,然后再次提示。否则,它将返回用户输入的数字。

这是我到目前为止所拥有的

    getNumberInRange(x,y):
        counter = 0
        answer = 0

    while counter < y:
        answer = answer + x
        counter = counter + 1
        return answer

最佳答案

您也可以尝试这种方法..

def getNumberInRange( low,high ):
   n1 = int(input("Enter a number:"))
   if ((n1 < low) or (n1 > high)):
       print("Please enter the number between the range "+ str(low) +" and "+ str(high))
       getNumberInRange(10,100)
   else :
       print(n1)
       return;
getNumberInRange(10,100)

关于python - 需要帮助创建具有两个参数的输入函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47785858/

相关文章:

Python 3.5 "ImportError: cannot import name ' 某个名字'

Django - ImageField Blank=True 不起作用

python - scikit 学习中 roc_curve 中的阈值

python - 将属性分配给类方法

python-2.7 - 基于行索引、列引用的数据框中的返回值

python - 在GAE控制面板中设置环境变量

python - 用于确定使用了哪个参数解包(位置或关键字)的内省(introspection)函数

javascript - 为什么在此示例中图像高度变得如此之大?

python - pytest 找不到 pytest.fixture_request

Python Minidom 修改/追加内容文件