将用户输入的值存储到变量(在函数中)

时间:2015-02-23 21:21:57

标签: python function loops

python新手。这是我正在看的内容

def input(check):

Check if the input by the user is bigger 0 and assign the user input result (Boolean) to a variable
Check if the input by the user is smaller than 180  and assign the user input result (Boolean) to another variable

如果两个变量都包含true,则返回true或其他情况返回False

如何编码?

2 个答案:

答案 0 :(得分:1)

input函数已内置于Python中。

def my_function():
    user_input = int(input('Enter a number: ')) # raw_input if Python 2

    a = user_input > 0
    b = user_input < 180

    return a and b # test if both are true

my_function() # call the function

答案 1 :(得分:0)

@Ravi您需要选择其他名称,因为input用于内置函数。您可以使用NewNameFunction编写所需的函数,如下所示:

def NewNameFunction (check):    
   a= check > 0
   b= check < 180   
   return (a and b)