2015-02-23 52 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) 
相關問題