2015-02-23 53 views
-5

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

感谢您分享您正在查看的内容。你有问题吗? – HavelTheGreat 2015-02-23 21:23:17

+0

我很抱歉。问题是如何去做... – 2015-02-23 21:24:00

+2

好吧。你可以请添加你的尝试到目前为止?这会让这里的人更愿意帮忙。通常很高兴看到一些你已经试过的代码,即使它不能满足你的需求。 – HavelTheGreat 2015-02-23 21:24:24

回答

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 
+0

为什么downvotes? – 2015-02-23 21:26:40

+0

一行返回:'return 0 2015-02-23 21:36:41

+0

OP要求存储为布尔值的值。 – 2015-02-23 21:40:20

0

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

def NewNameFunction (check):  
    a= check > 0 
    b= check < 180 
    return (a and b) 
相关问题